获取可变高度的iPhone 5/6/6的UIButton + [英] Get variable height for a UIButton for iPhones 5/6/6+
问题描述
有关我1)纵向仅2)部署目标iOS7 / iOS8上的应用程序,我有我的设计UIButtons它具有可变的高度,为iPhone 5,iPhone 6和iPhone 6+。我试图使用自动布局这一点。 (不使用大小类虽然)。
For my 1) portrait only 2) deployment target iOS7/iOS8 app, I have in my design UIButtons which have variable heights, for iPhone 5, iPhone 6 and iPhone 6+. I am trying to use auto layout for this. (Not using size classes though).
使用自动布局我怎么能指定的UIButton可变高度为这3个尺寸的屏幕。该按钮看起来在iPhone 5 *机型很好,但在iPhone六月六日+更薄。现在,在汽车的布局,我可以说高度> =或=或LT =说55),但我怎么对iPhone5的,55 iphone6,为iphone6 66 +
Using auto layout how can I specify variable height for UIButton for these 3 screen sizes. The buttons look fine on iPhones 5* models, but thinner on iphone 6/6+. Now in auto layout I can say height >= or = or <= say 55), but how do I specify 44 for iphone5, 55 for iphone6, 66 for iphone6+?
这是东西,我可以实现只使用自动布局或我需要manupulate(帧)它code?什么是使用自动排版那么我呢?
Is this something that I can achieve using only auto layout or do I need to manupulate (frames) it in code? What is the point of me using auto layout then?
在除了帧我的设计还可以指定不同的字体大小。我该如何去这件事。为此,堆栈-O的朋友最好的任何已知的方法??
In addition to frames my designs also specify different font sizes. How do I go about this. Any best known methods for this, Stack-O friends .. ??
推荐答案
这听起来像你需要进行修改高度限制恒定值。
It sounds like you need to be modifying the height constraints constant value.
在您的XIB /故事板,创建出口到您的视图/控制器的高度约束。
In your xib/storyboard, create an outlet to your view/controller for the height constraint.
在运行时,可能是在 viewDidLoad中
,你的工作,你是哪个设备,然后只需更改高度约束的常数。
At runtime, probably in viewDidLoad
, you will work out which device you're on, and then just change the constant of the height constraint.
CGFloat height;
// if iPhone 5
// height = 44
// else..........
self.buttonHeightConstraint.constant = height;
这将自动触发一个标志,告诉自动版式重新计算帧,并再次布局视图。
This will automatically trigger a flag that tells AutoLayout to recalculate frames and layout the view again.
这篇关于获取可变高度的iPhone 5/6/6的UIButton +的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!