[英]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.