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 (not to be confused with the front-end framework ) is the object-oriented framework that is responsible for most of the user interface. UIKit is part of the umbrella framework, and it is to Cocoa Touch as AppKit is to the Cocoa framework on macOS. The classes in UIKit determine the basic structure of most iOS applications as well as the majority of distinctive user interface elements that make iOS apps easily recognizable and instantly familiar.

UIKit provides the classes and protocols that lie at the foundation of any iOS application, including:

  • UIApplication
  • UIResponder
  • UIView
  • UIWindow
  • UIControl
  • UIEvent
  • UIViewController
  • UINavigationController
  • UITabBarController
  • UISplitViewController

It also provides the user interface elements with which all iOS users are familiar:

  • UIButton
  • UITextField
  • UITextView
  • UINavigationBar
  • UIToolbar
  • UITabBar
  • UISwitch
  • UILabel
  • UIScrollView
  • UITableView
  • UITableViewCell
  • UIPickerView

These lists are not exhaustive, but only meant to give a sense of the scope of the UIKit framework. A more complete list is found in the UIKit Framework Reference.

11807 questions
113
votes
17 answers

scale Image in an UIButton to AspectFit?

I want to add an image to a UIButton, and also want to scale my image to fit with the UIButton (make image smaller). Please show me how to do it. This is what I have tried, but it does't work: Adding image to button and using…
KONG
  • 7,271
  • 6
  • 28
  • 27
113
votes
16 answers

How to calculate the width of a text string of a specific font and font-size?

I have a UILabel that displays some chars. Like "x", "y" or "rpm". How can I calculate the width of the text in the label (it does not ues the whole available space)? This is for automatic layouting, where another view will have a bigger frame…
HelloMoon
112
votes
17 answers

How do I make UITableViewCell's ImageView a fixed size even when the image is smaller

I have a bunch of images I am using for cell's image views, they are all no bigger than 50x50. e.g. 40x50, 50x32, 20x37 ..... When I load the table view, the text doesn't line up because the width of the images varies. Also I would like small…
Robert
  • 37,670
  • 37
  • 171
  • 213
111
votes
6 answers

What are the differences between a UIView and a CALayer?

Both have most of the same attributes, both support different kind of animations, both represent different data. What are the differences between a UIView and a CALayer?
Oleg Danu
  • 4,149
  • 4
  • 29
  • 47
111
votes
6 answers

UIStackView Hide View Animation

In iOS 11 the behaviour of the hide animation within a UIStackView has changed, but I have been unable to find this documented anywhere. iOS 10 iOS 11 The code in both is this: UIView.animate(withDuration: DiscoverHeaderView.animationDuration, …
Infinity James
  • 4,667
  • 5
  • 23
  • 36
107
votes
6 answers

Passing arguments to selector in Swift

I'm programmatically adding a UITapGestureRecognizer to one of my views: let gesture = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(modelObj:myModelObj))) self.imageView.addGestureRecognizer(gesture) func…
mike
  • 2,073
  • 4
  • 20
  • 31
106
votes
4 answers

UIFont - how to get system thin font

UIFont has methods to get regular font (systemFontOfSize) or bold font (boldSystemFontOfSize), but how to get a "thin system font" available through storyboard? Passing "system-thin" to UIFont Contructor doesn't work, this constructor only works…
MiguelSlv
  • 14,067
  • 15
  • 102
  • 169
105
votes
11 answers

How can I get a precise time, for example in milliseconds in Objective-C?

Is there an easy way to get a time very precisely? I need to calculate some delays between method calls. More specifically, I want to calculate the speed of scrolling in an UIScrollView.
Thanks
  • 40,109
  • 71
  • 208
  • 322
102
votes
14 answers

UIStackView "Unable to simultaneously satisfy constraints" on "squished" hidden views

When my UIStackView "rows" are squished, they throw AutoLayout warnings. However, they display fine and nothing else is wrong besides these sorts of loggings: Unable to simultaneously satisfy constraints. Probably at least one of the…
Ben Guild
  • 4,881
  • 7
  • 34
  • 60
102
votes
4 answers

How to create a UIView bounce animation?

I have the following CATransition for a UIView called finalScoreView, which makes it enter the screen from the top: CATransition *animation = [CATransition animation]; animation.duration = 0.2; animation.type = kCATransitionPush; animation.subtype =…
WunDaii
  • 2,322
  • 4
  • 18
  • 26
100
votes
7 answers

Check if a subview is in a view

I'm making an app where I add a subview to a view using addSubview: on an IBAction. In the same way, when the button with that IBAction is touched again should call removeFromSuperview on that subview added on that IBAction: PSEUDO…
pmerino
  • 5,900
  • 11
  • 57
  • 76
99
votes
6 answers

UITableView + Add content offset at top

I need to add some blank space to the top of my UITableView that does not affect the size of the content area. Shifting the content down or adding a blank cell is NOT what I want to do. Instead I just want an offset. How?
bluefloyd8
  • 2,266
  • 2
  • 24
  • 20
98
votes
7 answers

UITableView disable swipe to delete, but still have delete in Edit mode?

I want something similar as the Alarm app, where you can't swipe delete the row, but you can still delete the row in Edit mode. When commented out tableView:commitEditingStyle:forRowAtIndexPath:, I disabled the swipe to delete and still had Delete…
willi
  • 6,559
  • 4
  • 30
  • 27
96
votes
3 answers

Difference between SceneDelegate and AppDelegate

In my SwiftUI project I see AppDelegate file as well as a SceneDelegate file. What are the differences between them? For example between the methods in SceneDelegate scene(_:willConnectTo:options:) and in the…
SwiftiSwift
  • 7,528
  • 9
  • 56
  • 96
94
votes
21 answers

Underline text in UIlabel

How can I underline a text that could be multiple lines of string? I find some people suggest UIWebView, but it is obviously too heavy a class for just text rendering. My thoughts was to figure out the start point and length of each string in each…
semix
  • 959
  • 1
  • 7
  • 4