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.
uiview
18,710
questions
637
votes
18
answers
306k
views
How to tell if UIViewController's view is visible
I have a tab bar application, with many views. Is there a way to know if a particular UIViewController is currently visible from within the UIViewController? (looking for a property)
633
votes
14
answers
229k
views
Cocoa: What's the difference between the frame and the bounds?
UIView and its subclasses all have the properties frame and bounds. What's the difference?
614
votes
21
answers
396k
views
Giving UIView rounded corners
My login view has a subview which has a UIActivityView and a UILabel saying "Signing In…". This subview has corners which aren't rounded. How can I make them round?
Is there any way to do it inside ...
568
votes
19
answers
692k
views
How to add constraints programmatically using Swift
I'm trying to figure this out since last week without going any step further. Ok, so I need to apply some constraints programmatically in Swift to a UIView using this code:
var new_view:UIView! = ...
552
votes
31
answers
400k
views
How to set cornerRadius for only top-left and top-right corner of a UIView?
Is there a way to set cornerRadius for only top-left and top-right corner of a UIView?
I tried the following, but it end up not seeing the view anymore.
UIView *view = [[UIView alloc] initWithFrame:...
450
votes
36
answers
336k
views
UIView with rounded corners and drop shadow?
I’ve been working on an application for a couple of years and received a simple design request: Round the corners on a UIView and add a drop shadow.To do as given below.
I want a custom UIView... : I ...
343
votes
22
answers
295k
views
Programmatically create a UIView with color gradient
I'm trying to generate a view with a gradient color background (A solid color to transparent) at runtime. Is there a way of doing that?
327
votes
6
answers
229k
views
UIView frame, bounds and center
I would like to know how to use these properties in the right manner.
As I understand, frame can be used from the container of the view I am creating.
It sets the view position relative to the ...
295
votes
17
answers
376k
views
How to add a touch event to a UIView?
How do I add a touch event to a UIView?
I try:
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, nextY)] autorelease];
[headerView addTarget:self ...
285
votes
42
answers
249k
views
How to find topmost view controller on iOS
I've run into a couple of cases now where it would be convenient to be able to find the "topmost" view controller (the one responsible for the current view), but haven't found a way to do it.
...
276
votes
9
answers
245k
views
How to set iPhone UIView z index?
I want to move one view on top of another, how can I know the z index of the view, and how to move on to top?
264
votes
28
answers
174k
views
UIView Infinite 360 degree rotation animation?
I'm trying to rotate a UIImageView 360 degrees, and have looked at several tutorials online. I could get none of them working, without the UIView either stopping, or jumping to a new position.
How ...
256
votes
10
answers
145k
views
How can I mimic the bottom sheet from the Maps app?
Can anyone tell me how I can mimic the bottom sheet in the new Apple Maps app in iOS 10?
In Android, you can use a BottomSheet which mimics this behaviour, but I could not find anything like that for ...
241
votes
8
answers
147k
views
iPhone - Get Position of UIView within entire UIWindow
The position of a UIView can obviously be determined by view.center or view.frame etc. but this only returns the position of the UIView in relation to it's immediate superview.
I need to determine the ...
230
votes
11
answers
85k
views
Autolayout - intrinsic size of UIButton does not include title insets
If I have a UIButton arranged using autolayout, its size adjusts nicely to fit its content.
If I set an image as button.image, the instrinsic size again seems to account for this.
However, if I ...
217
votes
4
answers
67k
views
Autoresizing masks programmatically vs Interface Builder / xib / nib
I was in an (probably false) assumption that enabling the right margin indicator in xib is equivalent to using UIViewAutoresizingFlexibleLeftMargin inside code and so on.
So, I used to think ...
213
votes
6
answers
162k
views
How to use UIVisualEffectView to Blur Image?
Could someone give a small example of applying the blur to an image? I've been trying to figure out the code for a while now :( still new at obj c!
The UIVisualEffectView provides a simple ...
201
votes
9
answers
166k
views
Is it possible to set UIView border properties from interface builder?
Is it possible to control UIView border properties (color, thickness, etc...) directly from interface builder or I can only do it programmatically?
201
votes
30
answers
155k
views
Get to UIViewController from UIView?
Is there a built-in way to get from a UIView to its UIViewController? I know you can get from UIViewController to its UIView via [self view] but I was wondering if there is a reverse reference?
201
votes
4
answers
111k
views
How do I apply a perspective transform to a UIView?
I'm looking to perform a perspective transform on a UIView (such as seen in coverflow)
Does anyonew know if this is possible?
I've investigated using CALayer and have run through all the pragmatic ...
198
votes
8
answers
85k
views
UIlabel layer.cornerRadius not working in iOS 7.1
I'm currently looking at a UILabel with the property addMessageLabel.layer.cornerRadius = 5.0f; On a device with iOS 7.0 installed, it has rounded corners. On a device with iOS 7.1 installed, it does ...
196
votes
3
answers
108k
views
UIView's frame, bounds, center, origin, when to use what?
UIView has the properties frame, bounds, center, and origin, and they all seem to be interrelated. Most of the time, I deal with frame when setting the position and size of a UIView. I understand ...
188
votes
27
answers
127k
views
Dashed line border around UIView
How do I add dashed line border around UIView.
Something Like this
185
votes
30
answers
259k
views
Load a UIView from nib in Swift
Here is my Objective-C code which I'm using to load a nib for my customised UIView:
-(id)init{
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"myXib" owner:self options:nil];
...
173
votes
13
answers
108k
views
iOS - forward all touches through a view
I have a view overlayed on top of many other views. I am only using the overaly to detect some number of touches on the screen, but other than that I don't want the view to stop the behavior of other ...
170
votes
35
answers
176k
views
How to add a border just on the top side of a UIView
My question is on the title.
I don't know how to add a border in a specific side, top or bottom, any side...
layer.border draws the border for the whole view...
168
votes
12
answers
147k
views
Given a view, how do I get its viewController?
I have a pointer to a UIView. How do I access its UIViewController? [self superview] is another UIView, but not the UIViewController, right?
168
votes
4
answers
73k
views
Proper practice for subclassing UIView?
I'm working on some custom UIView-based input controls, and I'm trying to ascertain proper practice for setting up the view. When working with a UIViewController, it's fairly simple to use the ...
162
votes
5
answers
152k
views
How do I write a custom init for a UIView subclass in Swift?
Say I want to init a UIView subclass with a String and an Int.
How would I do this in Swift if I'm just subclassing UIView? If I just make a custom init() function but the parameters are a String and ...
160
votes
8
answers
115k
views
iOS: verify if a point is inside a rect
Is there a way to verify if a CGPoint is inside a specific CGRect?
An example would be:
I'm dragging a UIImageView and I want to verify if its central point CGPoint is inside another UIImageView.
159
votes
11
answers
143k
views
Load view from an external xib file in storyboard
I want to use a view throughout multiple viewcontrollers in a storyboard. Thus, I thought about designing the view in an external xib so changes are reflected in every viewcontroller. But how can one ...
156
votes
7
answers
88k
views
Event handling for iOS - how hitTest:withEvent: and pointInside:withEvent: are related?
While most apple documents are very well written, I think 'Event Handling Guide for iOS' is an exception. It's hard for me to clearly understand what's been described there.
The document says,
In ...
153
votes
22
answers
155k
views
UIView bottom border?
To a UIScrollView *toScrollView (which is the width of the screen), I want to add a gray bottom border (exactly like that of the to-field of the compose view of the iPhone's native Messages app).
To ...
149
votes
24
answers
97k
views
Handling an empty UITableView. Print a friendly message
I have a UITableView that in some cases it is legal to be empty. So instead of showing the
background image of the app, I would prefer to print a friendly message in the screen, such as:
This list ...
142
votes
8
answers
214k
views
iPhone UIView Animation Best Practice
What is considered best practice for animating view transitions on the iPhone?
For example, the ViewTransitions sample project from apple uses code like:
CATransition *applicationLoadViewIn = [...
140
votes
8
answers
82k
views
How to control shadow spread and blur?
I have designed UI elements in sketch, and one of them has a shadow with blur 1 and spread 0. I looked at the doc for the views layer property and layer doesn't have anything named spread or blur, or ...
139
votes
24
answers
122k
views
How to convert a UIView to an image
I want to convert a UIView to an image and save it in my app. Can someone please tell me how to take screenshot of a view or convert it to an image and what is the best way to save it in an app (Not ...
139
votes
21
answers
80k
views
Completion block for popViewController
When dismissing a modal view controller using dismissViewController, there is the option to provide a completion block. Is there a similar equivalent for popViewController?
The completion argument is ...
139
votes
16
answers
107k
views
How Do I Take a Screen Shot of a UIView?
I am wondering how my iPhone app can take a screen shot of a specific UIView as a UIImage.
I tried this code but all I get is a blank image.
UIGraphicsBeginImageContext(CGSizeMake(320,480));
...
138
votes
9
answers
156k
views
How to draw a custom UIView that is just a circle - iPhone app
How would I go about drawing a custom UIView that is literally just a ball (a 2D circle)? Would I just override the drawRect method? And can someone show me the code for drawing a blue circle?
Also, ...
137
votes
8
answers
57k
views
iPhone SDK: what is the difference between loadView and viewDidLoad?
When working with views and view controllers in an iPhone app, can anyone explain the difference between loadView and viewDidLoad?
My personal context, is that I build all my views from code, I do ...
136
votes
14
answers
74k
views
Changing my CALayer's anchorPoint moves the view
I want to alter the anchorPoint, but keep the view in the same place.
I've tried NSLog-ing self.layer.position and self.center and they both stay the same regardless of changes to the anchorPoint. Yet ...
132
votes
9
answers
81k
views
Understand convertRect:toView:, convertRect:FromView:, convertPoint:toView: and convertPoint:fromView: methods
I'm trying to understand the functionalities of these methods. Could you provide me with a simple use case to understand their semantics?
From the documentation, for example, convertPoint:fromView: ...
130
votes
6
answers
137k
views
What is the most robust way to force a UIView to redraw?
I have a UITableView with a list of items. Selecting an item pushes a viewController that then proceeds to do the following. from method viewDidLoad I fire off a URLRequest for data that is required ...
129
votes
2
answers
91k
views
How does clipsToBounds work?
I would like to know how to use the UIView property clipsToBounds.
The official documentation says the following:
clipsToBounds property
A Boolean value that determines whether subviews are ...
128
votes
6
answers
84k
views
iOS: How does one animate to new autolayout constraint (height)
I've never worked with autolayout constraints before. I have a small new app I'm working on and noticed that the NIB's views are defaulting to autolayout. So, I figured I'd take the opportunity to ...
125
votes
14
answers
67k
views
Rounded UIView using CALayers - only some corners - How?
In my application - there are four buttons named as follows:
Top - left
Bottom - left
Top - right
Bottom - right
Above the buttons there is an image view (or a UIView).
Now, suppose a user taps on -...
123
votes
4
answers
100k
views
How do I create a custom iOS view class and instantiate multiple copies of it (in IB)?
I am currently making an app that will have multiple timers, which are basically all the same.
I want to create a custom class that uses all of the code for the timers as well as the layout/...
120
votes
8
answers
104k
views
When can I activate/deactivate layout constraints?
I've set up multiple sets of constraints in IB, and I'd like to programmatically toggle between them depending on some state. There's a constraintsA outlet collection all of which are marked as ...
119
votes
8
answers
79k
views
How do I change the color of the text in a UIPickerView under iOS 7?
I'm aware of the pickerView:viewForRow:forComponent:reusingView method, but when using the view it passes in reusingView: how do I change it to use a different text color? If I use view....