Questions tagged [uikit]
UIKit (not to be confused with the front-end framework GetUIKit) is the object-oriented framework that is responsible for most of the iOS user interface.
uikit
12,116
questions
2340
votes
51
answers
764k
views
Vertically align text to top within a UILabel
I have a UILabel with space for two lines of text. Sometimes, when the text is too short, this text is displayed in the vertical center of the label.
How do I vertically align the text to always be ...
582
votes
19
answers
295k
views
UITableViewCell, show delete button on swipe
How do I get the delete button to show when swiping on a UITableViewCell? The event is never raised and the delete button never appears.
570
votes
24
answers
234k
views
How to lose margin/padding in UITextView
I have a UITextView in my iOS application, which displays a large amount of text.
I am then paging this text by using the offset margin parameter of the UITextView.
My problem is that the padding of ...
565
votes
41
answers
431k
views
How do I size a UITextView to its content?
Is there a good way to adjust the size of a UITextView to conform to its content? Say for instance I have a UITextView that contains one line of text:
"Hello world"
I then add another line of text:
...
546
votes
18
answers
457k
views
How to get the screen width and height in iOS?
How can one get the dimensions of the screen in iOS?
Currently, I use:
lCurrentWidth = self.view.frame.size.width;
lCurrentHeight = self.view.frame.size.height;
in viewWillAppear: and ...
493
votes
38
answers
281k
views
iOS - Dismiss keyboard when touching outside of UITextField
I'm wondering how to make the keyboard disappear when the user touches outside of a UITextField.
391
votes
33
answers
208k
views
How do you add multi-line text to a UIButton?
I have the following code...
UILabel *buttonLabel = [[UILabel alloc] initWithFrame:targetButton.bounds];
buttonLabel.text = @"Long text string";
[targetButton addSubview:buttonLabel];
[targetButton ...
357
votes
16
answers
60k
views
UITableView didSelectRowAtIndexPath: not being called on first tap
I'm having an issue with UITableView's didSelectRowAtIndexPath.
My table is setup so that when I select row it initializes a new view controller and pushes it.
The first time I tap any row in the ...
348
votes
44
answers
294k
views
Move view with keyboard using Swift
I have an app that has a text field on the lower half of the view.
This means that when I go to type in the text field the keyboard covers the textfield.
How would I go about moving the view upwards ...
334
votes
38
answers
318k
views
UILabel text margin [duplicate]
I'm looking to set the left inset/margin of a UILabel and can't find a method to do so. The label has a background set so just changing its origin won't do the trick. It would be ideal to inset the ...
327
votes
34
answers
307k
views
Adjust UILabel height depending on the text
Consider I have the following text in a UILabel (a long line of dynamic text):
Since the alien army vastly outnumbers the team, players must use the post-apocalyptic world to their advantage, such ...
313
votes
18
answers
168k
views
How to capture UIView to UIImage without loss of quality on retina display
My code works fine for normal devices but creates blurry images on retina devices.
Does anybody know a solution for my issue?
+ (UIImage *) imageWithView:(UIView *)view
{
...
298
votes
6
answers
149k
views
How to trap on UIViewAlertForUnsatisfiableConstraints?
I'm seeing an error appear in my debugger log:
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x191f0920 H:[MPKnockoutButton:0x17a876b0]-(34)-[MPDetailSlider:0x17a8bc50](LTR)&...
292
votes
32
answers
265k
views
Changing Placeholder Text Color with Swift
I have a design that implements a dark blue UITextField, as the placeholder text is by default a dark grey colour I can barely make out what the place holder text says.
I've googled the problem of ...
288
votes
16
answers
229k
views
How to programmatically get iOS status bar height
I know that currently the status bar (with the time, battery, and network connection) at the top of the iPhone/iPad is 20 pixels for non-retina screens and 40 pixels for retina screens, but to future ...
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.
...
282
votes
25
answers
147k
views
preferredStatusBarStyle isn't called
I followed this thread to override -preferredStatusBarStyle, but it isn't called.
Are there any options that I can change to enable it? (I'm using XIBs in my project.)
282
votes
21
answers
269k
views
Aligning text and image on UIButton with imageEdgeInsets and titleEdgeInsets
Historic question. Note that 15 years later, .imagePadding is the space between the image and label.
Original question:
I would like to place an icon left of the two lines of text such that there's ...
254
votes
11
answers
171k
views
CGRectMake, CGPointMake, CGSizeMake, CGRectZero, CGPointZero is unavailable in Swift
After converting code to latest swift 3.0 I am shown this error.
Also tell me solution for CGSize = CGSizeMake(0,0)
static var frameAtStartOfPan: CGRect = CGRectZero
static var startPointOfPan: ...
252
votes
28
answers
244k
views
How to set back button text in iOS navigation controller?
How do you remove the back button text.
Current back button:
< Back
Desired back button:
< AnythingElse
None of these have worked:
self.navigationItem.backBarButtonItem?.title = "Back"
...
242
votes
24
answers
66k
views
How to stop unwanted UIButton animation on title change?
In iOS 7 my UIButton titles are animating in and out at the wrong time - late. This problem does not appear on iOS 6. I'm just using:
[self setTitle:text forState:UIControlStateNormal];
I would ...
227
votes
9
answers
126k
views
Is there a way to remove the separator line from a UITableView?
I'm looking for a way to completely remove the separator line in a UITableView when in the plain mode. This is done automatically in grouped, but this also changes the dimensions of the table in a way ...
225
votes
8
answers
93k
views
Disable the interactive dismissal of presented view controller
iOS 13 introduces a new design of modalPresentationStyle .pageSheet (and its sibling .formSheet) for modally presented view controllers…
…and we can dismiss these sheets by sliding the presented view ...
216
votes
18
answers
294k
views
How to change Navigation Bar color in iOS 7?
How do I change the Navigation Bar color in iOS 7?
Basically I want to achieve something like the Twitter Nav Bar (updated Twitter for iOS7 that is). I embedded-in a nav bar atop a view controller. ...
214
votes
31
answers
149k
views
Is it possible to disable floating headers in UITableView with UITableViewStylePlain?
I'm using a UITableView to layout content 'pages'. I'm using the headers of the table view to layout certain images etc. and I'd prefer it if they didn't float but stayed static as they do when the ...
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 ...
211
votes
22
answers
122k
views
Multiline label in UIStackView
When putting multiline label (with linebreak set to Word Wrap) into a stack view, the label immediately loses the linebreak and displays the label text in one line instead.
Why is this happening and ...
199
votes
15
answers
259k
views
UICollectionView spacing margins
I have a UICollectionView which shows photos. I have created the collectionview using UICollectionViewFlowLayout. It works good but I would like to have spacing on margins. Is it possible to do that ...
198
votes
11
answers
138k
views
Adding the "Clear" Button to an iPhone UITextField
How do you add that little "X" button on the right side of a UITextField that clears the text? I can't find an attribute for adding this sub-control in Interface Builder in the iPhone OS 2.2 SDK.
...
197
votes
36
answers
103k
views
UIButton: Making the hit area larger than the default hit area
I have a question dealing with UIButton and its hit area. I am using the Info Dark button in interface builder, but I am finding that the hit area is not large enough for some people's fingers.
Is ...
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 ...
190
votes
17
answers
141k
views
Get UIScrollView to scroll to the top
How do I make a UIScrollView scroll to the top?
184
votes
19
answers
192k
views
How to Rotate a UIImage 90 degrees?
I have a UIImage that is UIImageOrientationUp (portrait) that I would like to rotate counter-clockwise by 90 degrees (to landscape). I don't want to use a CGAffineTransform. I want the pixels of the ...
178
votes
11
answers
91k
views
How do I inspect the view hierarchy in iOS?
Is there a GUI tool that inspects the view hierarchy of an iOS app? I'm thinking about Webkit's web inspector or similar tools. I'm looking to debug layout issues, like views having the wrong position ...
173
votes
12
answers
142k
views
How do you get an iPhone's device name
If you open Settings -> General -> About, it'll say Bob's iPhone at the top of the screen. How do you programmatically grab that name?
172
votes
16
answers
50k
views
Achieving bright, vivid colors for an iOS 7 translucent UINavigationBar
iOS 7.1 UPDATE: Looks like the workaround for modifying the alpha channel in the UINavigationBar has been ignored in this update. Right now, the best solution seems to be to just 'deal with it' and ...
171
votes
11
answers
181k
views
How can I delay a method call for 1 second?
Is there an easy way delay a method call for 1 second?
I have a UIImageView that reacts on a touch event. When the touch is detected, some animations happen in the app. After one second, I want to ...
170
votes
13
answers
73k
views
Detecting sheet was dismissed on iOS 13
Before iOS 13, presented view controllers used to cover the entire screen. And, when dismissed, the parent view controller viewDidAppear function were executed.
Now iOS 13 will present view ...
169
votes
18
answers
121k
views
Is it possible to Turn page programmatically in UIPageViewController?
Is it possible to turn page programmatically in UIPageViewController?
166
votes
13
answers
121k
views
Using HTML and Local Images Within UIWebView
I have a UIWebView in my app which I want to use to display an image which will link to another url.
I'm using
<img src="image.jpg" /> to load the image.
The problem is that the image doesn't ...
164
votes
14
answers
96k
views
How to disable the highlight control state of a UIButton?
I've got a UIButton that, when selected, shouldn't change state when being touched.
The default behaviour is for it to be in UIControlStateHighlighted while being touched, and this is making me angry.
...
159
votes
23
answers
372k
views
Make a UIButton programmatically in Swift
I am trying to build UIs programmatically with Swift.
How can I get this action working?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, ...
157
votes
10
answers
72k
views
What's the point of NSAssert, actually?
I have to ask this, because: The only thing I recognize is, that if the assertion fails, the app crashes. Is that the reason why to use NSAssert? Or what else is the benefit of it? And is it right to ...
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 ...
154
votes
9
answers
136k
views
How to draw border around a UILabel?
Is there a way for UILabel to draw a border around itself? This is useful for me to debug the text placement and to see the placement and how big the label actually is.
153
votes
10
answers
100k
views
How do I wrap text in a UITableViewCell without a custom cell
This is on iPhone 0S 2.0. Answers for 2.1 are fine too, though I am unaware of any differences regarding tables.
It feels like it should be possible to get text to wrap without creating a custom cell,...
151
votes
18
answers
96k
views
How to change the colors of a segment in a UISegmentedControl in iOS 13?
A UISegmentedControl has a new appearance in iOS 13 and existing code to alter the colors of the segmented control no longer work as they did.
Prior to iOS 13 you could set the tintColor and that ...
148
votes
8
answers
143k
views
How to calculate UILabel width based on text length?
I want to display an image next to a UILabel, however UILabel has variable text length, so I don't know where to place the image. How can I accomplish this?
143
votes
11
answers
90k
views
Using a custom image for a UITableViewCell's accessoryView and having it respond to UITableViewDelegate
I'm using a custom drawn UITableViewCell, including the same for the cell's accessoryView. My setup for the accessoryView happens by the way of something like this:
UIImage *accessoryImage = [UIImage ...
141
votes
9
answers
160k
views
UITextField border color
I have really great wish to set my own color to UITextField border. But so far I could find out how to change the border line style only.
I've used background property to set background color in such ...