[英]Button image sizes not changing in iPad by autolayout using iOS?
您必須基於percentage(%)
添加約束,以便按鈕圖像可以根據device
(iPhone / iPad) screen size
。
按鈕上的StoryBoard約束
Step 1. Drag button and place it on its proper position.
Step 2. Now Add constraint Horizontal Center in Container.
Step 2. Now Add Bottom Pin constraint.
Step 3. Add constraint Equal Width and Equal Height.
Step 4. Now update multiplier of Equal Width constraint and Equal Height.
通過使用KVConstraintExtensionsMaster
以編程方式更新iPad上的約束。
- (void)viewDidLoad
{
[super viewDidLoad];
/* preparing View Hierarchy */
UIButton *button = [UIButton prepareNewViewForAutoLayout];
[self.view addSubview:button];
/* applying constraints */
[button applyConstraintForHorizontallyCenterInSuperview];
[button applyBottomPinConstraintToSuperviewWithPadding:defualtConstant];
[button applyWidthConstraint:280]; // fixed width for iphone
[button applyHeightConstrain:40]; // fixed height for iphone
// update width constraint with proper iPad ratio
[button updateAppliedConstraintConstantValueForIpadByAttribute:NSLayoutAttributeWidth];
// update height constraint with proper iPad ratio
[button updateAppliedConstraintConstantValueForIpadByAttribute:NSLayoutAttributeHeight];
/*
// update Height constraints at any specific ratio on iPad
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[button updateAppliedConstraintConstantValueByAttribute:NSLayoutAttributeHeight withConstantRatio:1.8];
}
*/
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.