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
5
votes
4 answers

Button not working in UITableViewCell subclass when it is a subview of a view inside the UITableViewCell

I have a button in a tableView Cell that I need to respond to touch events. Normally this would easily be solved by [cell.playButton addTarget:self action:@selector(playButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; inside of…
Joel Bell
  • 2,718
  • 3
  • 26
  • 32
5
votes
1 answer

iOS: sending email with attachment adds another attached (.txt) file automatically

I am using the following code to send an email with the contents of NSData object(with the variable name: data): MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init]; [controller setSubject:@"Subject"]; [controller…
Petar
  • 2,241
  • 1
  • 24
  • 38
5
votes
1 answer

Iterate over all subviews of a specific type

Iterating over all UIViews in the subviews of a class and then checking the type in the loop using isKindOfClass made my code look redundant. So I wrote the following method which executes a block for each subview. @implementation Util +…
Nils
  • 13,319
  • 19
  • 86
  • 108
5
votes
3 answers

reload/refresh subViews - setNeedsDisplay doesnt work

i have trouble with setNeedsDisplay. I have an UIView with a lot of sub UIViews, created in Inteface Builder. I have also an Button with IBAction. In this IBAction i want to redraw/reload all UIViews (or all UIElements, like UILabel, UIWebView and…
brush51
  • 5,691
  • 6
  • 39
  • 73
5
votes
3 answers

How to create a small popup in iOS?

I'm looking for the simplest code in order to implement a small popup (NOT a full screen modal popup or alert view). I just need it to display some basic text inside the popup, then exit it when I click away. The popup in the EleMints app is a good…
Radrider33
  • 557
  • 1
  • 4
  • 17
5
votes
1 answer

iOS - animating UIView on iPad, change x origin and width simultaneously?

I'm having some trouble with UIView animations on iPad. I'm working on a project in which I have implemented a "facebook style" menu on the left, using the JTRevealSidebar framework. This framework works perfectly, however, instead of "pushing" the…
Mutix
  • 4,196
  • 1
  • 27
  • 39
5
votes
1 answer

iOS gradient transpareny mask over animated view

Hello, Looking for insight from the gurus. I need a stack of 3 views: A: View containing various buttons, text inputs. B: Custom view containing a large view (B2) that moves and rotates and contains multiple subviews and another fixed view (B1)…
Ty Kroll
  • 1,385
  • 12
  • 27
5
votes
1 answer

UIView draw shadow beyond view's frame

I have a requirement where I have to draw a view's shadow beyond the view's frame. We already have complex view hierarchy / layering and it would not be possible now to change the view's frames and layout to accommodate the shadows within the…
Raj Pawan Gumdal
  • 7,390
  • 10
  • 60
  • 92
5
votes
3 answers

why is UIWindow a child and also a parent of UView?

The UIKit reference says UIView is a superclass of UIWindow, but despite of this parentage, a UIWindow actually manages UIViews. This sounds so unusual to me. Does anyone know what the significants of this are in terms of software design? Many…
Martin08
  • 20,990
  • 22
  • 84
  • 93
5
votes
1 answer

Is willMoveToSuperview called (with nil) when removing a view from a hierarchy?

If you implement willMoveToSuperview on a UIView subclass, is it guaranteed to be called (with nil) when removeFromSuperview is called on your view? The docs say that the newSuperview parameter may be nil and that it's called "whenever the superview…
jhabbott
  • 18,461
  • 9
  • 58
  • 95
5
votes
5 answers

UIView CAGradient with rounded corners?

I have an UIView with rounded corners and drop shadow, implemented and working. But the UIView has a boring background color, white. So I want to put a gradient layer as the background. Below the labels, buttons and most important, make it so the…
Jacob
  • 1,310
  • 1
  • 15
  • 29
5
votes
2 answers

iOS app gets completely misaligned when switching from 5 to 4.3 in simulator

I'm working on an app that is ideally targeted all the way down to iOS 3.2. Still, I am developing it on Lion and with the latest 5 sdk. As far as I know, I am not using any sdk 5 specific features. But: on any devices with iOS 5 or the simulator…
SaldaVonSchwartz
  • 3,769
  • 2
  • 41
  • 78
5
votes
4 answers

Changing Backgroundcolor of the UIView through code intead of XIB in ios

I created a windowbased project,then I added a new viewcontroller with xib for user interface checked,and then by entering into the xib,I made some customization to the view,I added few buttons and also changed the background color, But now I want…
Ranjit
  • 4,576
  • 11
  • 62
  • 121
5
votes
2 answers

Overlaying UIView with an background image

Is it possible to overlay UIView with an image without using UIImageView from the Interface Builder? If not, how would you accomplish the same in code?
James Raitsev
  • 92,517
  • 154
  • 335
  • 470
5
votes
2 answers

How to prevent UIView from being resized to fit ScrollView height (autoresizing disabled)?

I'm writing a PDF reader using vfr-reader library. To display two pages in landscape i'm rendering each page into its own view, then add these two views to a container view, then add container view to a scroll view. Each view's autoresizingMask is…
Spail
  • 693
  • 1
  • 7
  • 21
1 2 3
99
100