Questions tagged [uiview]

UIView is a class in the UIKit framework of iOS defines a rectangular area on the screen and the interfaces for managing the content in that area. All UI elements are either subclasses of UIView or are contained within a UIView.

The UIView class defines a rectangular area on the screen and the interfaces for managing the content in that area. At runtime, a view object handles the rendering of any content in its area and also handles any interactions with that content. The UIView class itself provides basic behavior for filling its rectangular area with a background color. More sophisticated content can be presented by subclassing UIView and implementing the necessary drawing and event-handling code yourself. The UIKit framework also includes a set of standard subclasses that range from simple buttons to complex tables and can be used as-is. For example, a UILabel object draws a text string and a UIImageView object draws an image.

Because view objects are the main way your application interacts with the user, they have a number of responsibilities. Here are just a few:

Drawing and animation

  • Views draw content in their rectangular area using technologies such as UIKit, Core Graphics, and OpenGL ES.

  • Some view properties can be animated to new values.

Layout and subview management

  • A view may contain zero or more subviews.

  • Each view defines its own default resizing behavior in relation to its parent view.

  • A view can define the size and position of its subviews as needed.

Event handling

  • A view is a responder and can handle touch events and other events defined by the UIResponder class.
  • Views can use the addGestureRecognizer: method to install gesture recognizers to handle common gestures.

Views can embed other views and create sophisticated visual hierarchies. This creates a parent-child relationship between the view being embedded (known as the subview) and the parent view doing the embedding (known as the superview). Normally, a subview’s visible area is not clipped to the bounds of its superview, but in iOS you can use the clipsToBounds property to alter that behavior. A parent view may contain any number of subviews but each subview has only one superview, which is responsible for positioning its subviews appropriately.

The geometry of a view is defined by its frame, bounds, and center properties. The frame defines the origin and dimensions of the view in the coordinate system of its superview and is commonly used during layout to adjust the size or position of the view. The center property can be used to adjust the position of the view without changing its size. The bounds defines the internal dimensions of the view as it sees them and is used almost exclusively in custom drawing code. The size portion of the frame and bounds rectangles are coupled together so that changing the size of either rectangle updates the size of both.

For detailed information about how to use the UIView class, see View Programming Guide for iOS.

Creating a View

To create a view programmatically, you can use code like the following:

CGRect  viewRect = CGRectMake(10, 10, 100, 100);
UIView* myView = [[UIView alloc] initWithFrame:viewRect];

Equivalent in Swift is:

let viewRect = CGRectMake(10, 10, 100, 100)
let myView = UIView(frame: viewRect)
18705 questions
6
votes
0 answers

How to use a UIView with a CCLayer cocos2d?

I am playing a short video with CCVideoPlayer in cocos2d and at the end of it I am capturing the very last frame of the video and I am showing it on the screen using a UIView because trying to draw it on a CCLayer makes the image show up with…
Stephen
  • 499
  • 9
  • 28
6
votes
2 answers

how to make Irregular shape uiview and put uiimageview inside those shapes like instacollage iphone app

I am working on a photo collage iphone app and i have to make irregular shape photo frames inside each shape there will be a uiimageview with gestures, on tapping the shape i need to pick a photo for that shape, these frames are very similar to…
6
votes
2 answers

UIView Drawing Best Practices

My application is able to do some simple figure's drawing (until I get a more stable code, I am sticking with only one figure) and it's also able to re-size them. The code I use to create a UIView is the following : - (void)drawRect:(CGRect)rect { …
Rui Peres
  • 25,741
  • 9
  • 87
  • 137
6
votes
1 answer

iOS Colorwithpattern - using a custom iPhone5 image

For my app's loading screen and splash screen, I used up with two different methods to display my iPhone 3, iPhone 4 and iPhone 5 images appropriately. For the loading screen, simply adding -568h@2x to your image is enough to support iPhone5. For…
Mark S
  • 2,161
  • 3
  • 21
  • 25
6
votes
3 answers

Can you override a parent UIView's alpha value on one of its subviews?

I have a somewhat transparent view (alpha = 0.6) that has some subviews. I'd like one of the subviews (a UILabel) to be drawn with alpha of 1.0 because the blending makes the text difficult to read but by adding it as a subview of the main view it…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
6
votes
1 answer

How to set programmatically topBar and bottomBar parameters of UIView?

In the interface builder there are few parameters for UIView of UIViewController: topBar, bottomBar, ... interface builder parameters of view What happens when i set Navigation Bar value for Top Bar parameter, and Tab bar for Bottom Bar parameter?…
BergP
  • 3,453
  • 4
  • 33
  • 58
6
votes
1 answer

Using CATransformLayer warning: changing property opaque in transform-only layer, will have no effect

I created a "TransformView" subclassing UIView in order to support a double-sided view which I am using in a flip animation. This has been suggested in other posts, eg: How to rotate a flat object around its center in perspective view? @interface…
Bbx
  • 3,184
  • 3
  • 22
  • 33
6
votes
1 answer

ios animation like emailing photo

I'm really curious as to how apple does this transition: If you go to a photo within the photos app, then try to send it in an email, you'll see this pretty cool transition where Apple grabs the image, slides up a modal email vc, then places the…
Sean Danzeiser
  • 9,141
  • 12
  • 52
  • 90
6
votes
1 answer

simplest (rectangular) drop shadow for an UIView

I've seen lots of snippets that either: are too complicated for something as simple as a drop shadow, requiring subclassing UIView and using quartz2d calls, or I can't get them to work. I just want to do this on a view I'm adding as a subview to…
maltalef
  • 1,507
  • 2
  • 16
  • 27
6
votes
2 answers

How should a UIView get references to its children?

I have a xib with a root view that is a UIView subclass. How should this view get references to the child views I declared in Interface Builder? Obviously a ViewController can be wired up with outlets, but what about a UIView?
Undistraction
  • 42,754
  • 56
  • 195
  • 331
6
votes
4 answers

UIPanGestureRecognizer limit to coordinates

I added to my main UIView a subview (called panel) and i added gestureRecognizer to it because i want it to be draggable only for the Y axis and only for certain limits (i.e. 160, 300, over 300 it can't go). I implemented the gesture handling that…
Phillip
  • 4,276
  • 7
  • 42
  • 74
6
votes
1 answer

UIBezierPath - Animating Fill

I have a UIBezierPath (a circle) built incrementally with: [circlePath addArcWithCenter:clockCenter radius:radius startAngle:angleRadians endAngle:1.5*M_PI clockwise:YES]; ... [circlePath closePath]; [COLOR_CIRCLE setFill]; [circlePath…
Michael Mangold
  • 1,741
  • 3
  • 18
  • 32
6
votes
2 answers

iPhone iOS how to add pin/passcode lock screen when app resumes from background?

I need to add a 4 digit pin view controller that would "hover" over my app's main window and prevent users who do not know the pin from browsing data within the app. I'm interested if there are any demo projects or open source projects that…
Alex Stone
  • 46,408
  • 55
  • 231
  • 407
6
votes
7 answers

Remove a view from one view and add it to another

I am trying to find all my views that are in the nib and add them to my content view. This is what I have, It successfully removes the view from self.view but it does not add it to self.contentView for (UIView *view in self.view.subviews) { if…
Gary Kagan
  • 139
  • 2
  • 7
6
votes
5 answers

UIActionSheet taking long time to respond

I am creating a UIActionSheet on actionSheet:clickedButtonAtIndex delegate method. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex if(buttonIndex == 1){ [self.myFirstView…
Xavi Valero
  • 2,047
  • 7
  • 42
  • 80