autolayout

What do you apply auto layout constraints to line up labels with background image elements?

那年仲夏 提交于 2019-12-24 13:54:06
问题 See the screenshot below for the example but here is the issue. I have 3 text labels and I'm trying to line those labels up with 3 circles that are part of an Image View. It appears the issue is caused when the image is set to Aspect Fit and gets scaled along with the various iPhone sizes. I can align the text labels horizontally but I cannot figure out how to set the vertical constraints to "scale" properly. Any suggestions or direction would be awesome, thanks! 回答1: Are you setting constant

Turning off “Use Autolayout” causes app to only run in portrait mode

不想你离开。 提交于 2019-12-24 13:30:24
问题 I want my app to be compatible with iOS 5, so I had to disable "Use Autolayout" in the XIB files. The whole app is designed to be run in landscape mode. When the app is launched after disabling autolayout (whether in iOS 5 or iOS 6), the app always launches in portrait mode and refuses to rotate to landscape. In Info.plist, Supported Interface Orientations (iPad) is set only to landscape. What am I doing wrong? This only occurs after disabling autolayout. 回答1: I was able to fix the issue in

Size of images for UI for different screen sizes?

為{幸葍}努か 提交于 2019-12-24 13:21:59
问题 If I want to set a button's background image in iOS in an app that uses autolayout, what size should the .png image be? Since the height, and width of the button will always vary, in addition to accommodating for retina/nonretina displays (@2x?). 回答1: You can add multiple images with providing proper naming conventions normal, @2x, @3x, ~iPad etc. For that go through Apple documentations. For example, your image name is myBackground.png then [UIImage imageForDeviceWithName:@"myBackground"];

Top constraint won't get less with auto-layout

江枫思渺然 提交于 2019-12-24 12:34:25
问题 I'm trying to get to work with auto-layout in my storyboard. My first two views worked well, the UIViews that are in the views do not resize, and just get centered in my view by lowering the top and bottom constraint . Now in my third view, I'm having some issues. The top constraint won't get less. Already tried like 3 hours but still cannot figure it out by myself. Am I doing something wrong? I've already tried to: Hook the right top UIView to my left top UIView Insert an right or left and

Views disappear when `translatesAutoresizingMaskIntoConstraints` set `NO`

冷暖自知 提交于 2019-12-24 10:57:31
问题 Problem Some third party library is used. Some views disappear after their translatesAutoresizingMaskIntoConstraints are set to NO . Don't have other autoresizingMask setting for my views in my own code; in the library, the autoresizingMask parts of code have been removed too. Instead, explicit bounds/center/frame are set for those views. There're no nib files, views are all programmatically created. I know some other people solve similar problem by giving a thorough autolayout constraints

Change NSLayoutConstraint constant not working in layoutSubviews

两盒软妹~` 提交于 2019-12-24 10:39:26
问题 I am trying to change a UIButton's width when the view animates to landscape mode. But the method is called because I set a break point there, but the button's width doesn't change. I add a IBOutlet constraint to button's width named: globalButtonWidthConstraint. My current code : - (void)layoutSubviews { [super layoutSubviews]; CGSize screenSize = [[UIScreen mainScreen] bounds].size; CGFloat screenH = screenSize.height; CGFloat screenW = screenSize.width; BOOL isLandscape = !(self.frame.size

Constrains count is always getting zero ( 0 ) in AutoLayout - iOS

社会主义新天地 提交于 2019-12-24 10:38:23
问题 I am getting one weird issue, I am setting constraints on the view using storyboard as below: But if I am accessing all applied constraint by code then always getting zero (0). for self.view it's returning the constraint but for yellow view getting zero. 回答1: Use this code (Swift 4+ and Xcode 9.4.1) import UIKit class ViewController: UIViewController { @IBOutlet var subView: UIView! override func viewDidLoad() { super.viewDidLoad() print(self.view.getAllConstraints().count) print(self.subView

Programming autolayout swift

偶尔善良 提交于 2019-12-24 09:40:10
问题 I have in app: TextView and TableView. I create their in code. And now I need to make programming autolayout. But I don't know how it make. Please help. P.S. Sorry for my English =) let displayWidth: CGFloat = self.view.frame.width let displayHeight: CGFloat = self.view.frame.height myTextView = UITextView(frame: CGRect(x: 0, y: 20, width: displayWidth, height: displayHeight / 3)) creatTextView() myTableView = UITableView(frame: CGRect(x: 0, y: displayHeight / 3, width: displayWidth, height:

How do I change the font size according to screen size

梦想的初衷 提交于 2019-12-24 08:12:36
问题 I have added min font size to label but the font is not changing according to the screen size. I thought setting min font size and using autolayout is to scale the label height is enough. But its not happening. 回答1: Use minimum font scale instead of minimum font size. Minimum font size was deprecated in IOS 6. In the image although mine says fixed here you can change that and then set the scale factor. To vary by size of the screen you can do some of that with interface builder. See image.

Design UIView subclass auto layout with custom size in Interface Builder xib file

冷暖自知 提交于 2019-12-24 08:09:03
问题 I have an UIView subclass with its layout in a .xib file. I set the size to freeform and the dimensions to something like 200 x 300. How can I set different dimensions for iPad so the "View as" option correctly show a preview of how it would look like? Or, can this be achieved in a different way? Maybe using a storyboard instead of a xib file? 回答1: Similar kind of feature I did last week. I had an xib file and that I was using as a collectionView item. Through interface builder it cannot be