nslayoutconstraint

Correct way to programmatically update constraints when the device orientation changes?

我怕爱的太早我们不能终老 提交于 2020-01-13 09:01:26
问题 I'm using storyboard and autolayout , and setting the constraints in IB as IBOutlet in the corresponding view controller. I'm reading several posts regarding how to update the constraints to be different in portrait and in landscape but I'm still not sure of how should I do this: Should I set the new constraints in -viewWillTransitionToSize:withTransitionCoordinator: method, or in updateViewConstraints method? When the new constraints are set, should I call [self.view

Migrating project to Xcode 7.2 on OS X El Capitan breaks the build

我们两清 提交于 2020-01-13 02:16:12
问题 I was running OS X Mavericks before with Xcode 7.1, I just updated to OS X El Capitan and Xcode 7.2. My app was launching fine on the simulator and device without any kind of warnings for storyboard. Now I see a bunch of warnings for missing constraints in storyboard and the app crashes with this error: Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named IBNSLayoutConstraint' I also tried the solution posted on here :

IOS自动布局

主宰稳场 提交于 2020-01-11 03:49:55
参考资料 https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage/VisualFormatLanguage.html#//apple_ref/doc/uid/TP40010853-CH3 https://developer.apple.com/library/ios/technotes/tn2154/_index.html https://developer.apple.com/library/mac/documentation/AppKit/Reference/NSLayoutConstraint_Class/NSLayoutConstraint/NSLayoutConstraint.html 开源项目Masonry旨在让自动布局(Auto Layout)的代码更简洁、可读性更强,下面是它的地址,个人认为在开发过程中使用Masonry可以是代码更加友好 https://github.com/cloudkite/Masonry - (void)viewDidLoad { [super viewDidLoad]; [self addNavigationBar:FEEDBACK_VIEW_CONTROLLER];

技巧

泪湿孤枕 提交于 2020-01-11 02:08:12
1、 -(void)performSelector { SEL selector = @selector(printImp); IMP imp = [self methodForSelector:selector]; void (*setter)(id,SEL,BOOL) = (void(*)(id,SEL,BOOL))imp; setter(self,selector,YES); } -(void)printImp { NSLog(@"MemoryCollectPerformance Print....."); } 2、了解API以下的东西的话,依然可以利用Obj-C的runtime。 可以在这里看到 http://opensource.apple.com/source/objc4/objc4-493.11/runtime/ ,尤其是objc-runtime.m, 这里提供了很多学习用的"工具"。比如经典的method_exchangeImplementations(),您可以用它研究很多黑箱过程的来龙去脉。值得一提的是, 这种技巧(method swizzling)是合法的,可以在App Store 中使用! 苹果曾给使用了相关技巧的开发者发过邮件,表示出于安全性和稳定性最好不再使用, 但没有禁止。 3、界面布局 // 1、AutoLayout 手写 UIEdgeInsets

How to make UILabel and UITextField font size to be relative to screen size

喜夏-厌秋 提交于 2020-01-07 05:43:05
问题 I have a view controller which has a text field and label and I have set height constraint for text field and label and so I feel font size is not relative to the screen I believe. How can I make this items' font size to be relative to the screen size? 回答1: You can manually change UIlabel or UITextfield font in viewDidLayoutSubviews method of your ViewController or layoutSubviews method of your superView . Like this: CGRect screenSize = [UIScreen mainScreen].bounds; textField.font = [UIFont

How to make UILabel and UITextField font size to be relative to screen size

本秂侑毒 提交于 2020-01-07 05:42:12
问题 I have a view controller which has a text field and label and I have set height constraint for text field and label and so I feel font size is not relative to the screen I believe. How can I make this items' font size to be relative to the screen size? 回答1: You can manually change UIlabel or UITextfield font in viewDidLayoutSubviews method of your ViewController or layoutSubviews method of your superView . Like this: CGRect screenSize = [UIScreen mainScreen].bounds; textField.font = [UIFont

Why is my layout constraint returning an error in this case? (Swift)

半腔热情 提交于 2020-01-06 15:51:36
问题 I am trying to peg a label (progressTimer label) 10 units to the left of my slider (sliderDemo). I am using the following constraint but for some reason my application keeps on crashing. I can't seem to find anything wrong with it. Any help would be greatly appreciated! var constS1 = NSLayoutConstraint(item: progressTimerLabel, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: sliderDemo, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 10)

On rotation cell height gets lost on iOS 8 when using auto layout

荒凉一梦 提交于 2020-01-06 07:14:53
问题 Normally iOS 8 should be able to calculate the height of a cell itself. This is working so far, but if I rotate the device the cell gets back to its standard height of 44 points. This is how it should look like: This is how it does look like after rotation: Once rotated it stays in that layout. It never calculates the real height anymore. I don't know why. I have added my complete code. For the constraints have a look into updateConstraints . The code is in C# but you should be able to read

create a loop to space 2 different objects on a uiviewcontroller

不打扰是莪最后的温柔 提交于 2020-01-06 05:25:29
问题 My code below does exactly what I am looking for the problem is it just does this in a uibtton. I would like to do the same thing with 2 uitextfields and 2 uilabels. So textfield to uilabel to textfield to uilabel. I assume you would just have to change "button in" but I dont know what to change it with. I want the objects spaced 40 between each other just like below. func setConstraints() { var yPosition: CGFloat = 0 [undoButton, clearButton, color].forEach { button in NSLayoutConstraint

How can I programatically constrain UIButtons in a UIView to proportional widths using NSLayoutConstraints

家住魔仙堡 提交于 2020-01-05 08:06:30
问题 I am trying to create a custom keyboard programatically. I have managed to get the functionality of the keyboard working but am struggling with setting the constraints programatically. I have managed to find code to constrain the buttons to be equal sizes in their rows but cannot customise it enough to set the width (or proportional width) of certain buttons. Here is a picture of the keyboard currently Each row is a separate UIView filled with UIButtons corresponding to each key. I then