[英]How to create custom UICollectionViewCell using Storyboard in iOS?
[英]How to create ImageView center on storyboard using iOS?
我正在嘗試使用Xcode 7和iOS 9中的iOS故事板創建通用應用程序。在故事板概念中,我可以看到許多方法(自動布局,自動約束,自適應UI等)。 我對這些設計方法感到困惑。 請給我一個解決方案,為所有iPhone和iPad的中心圖像視圖顯示。
如果你想在iOS中設計通用應用程序,那么你必須根據percentage(%)
添加約束。很少有情況或情況你不能從Starboard添加約束但不要擔心我們可以做到這一點編程。
你有沒有嘗試過KVConstraintExtensionsMaster
庫來應用我已經實現的約束。 該庫具有update
, apply
, access
和remove
通過Programmatically
或從Interface Builder(StoryBoard/xib)
應用的約束的方法。
以編程方式在所有iPhone和iPad的中心上顯示imageView。
- (void)viewDidLoad
{
[super viewDidLoad];
/* preparing View Hierarchy */
UIImageView *imageView = [UIImageView prepareNewViewForAutoLayout];
[self.view addSubview:imageView];
[imageView setBackgroundColor:[UIColor blueColor]];
/* applying constraints */
[imageView applyConstraintForCenterInSuperview];
/* Change the Ratio 0.0 to 1.0 to vary the height and width */
[imageView applyEqualHeightRatioPinConstrainToSuperview:0.8];
[imageView applyEqualWidthRatioPinConstrainToSuperview:0.8];
/* Comment the above both RatioPinConstrainToSuperview methods and uncomment below methods and run on both iPhone or iPad and see the magic.*/
/*
[imageView applyWidthConstraint:280]; // fixed width for iphone
[imageView applyHeightConstrain:280]; // fixed height for iphone
// update width constraint with proper iPad ratio
[imageView updateAppliedConstraintConstantValueForIpadByAttribute:NSLayoutAttributeWidth];
// update height constraint with proper iPad ratio
[imageView updateAppliedConstraintConstantValueForIpadByAttribute:NSLayoutAttributeHeight];
*/
}
從StoryBoard imageView顯示在所有iPhone和iPad的中心。
步驟1.在ViewController視圖中拖放imageView。
步驟2.現在在Container中添加約束Horizontal Center和在Container中添加Vertical Center。
步驟3.添加約束Equal Width和Equal Height。
步驟4.現在更新Equal Width約束和Equal Height的乘數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.