我正嘗試在Xcode 7和iOS 9中使用iOS Storyboard創建通用應用程序。在故事板概念中,我可以看到很多方法(自動佈局,自動約束,自適應UI等)。我對這些設計方法感到困惑。請給我一個針對所有iPhone和iPad中心的圖像視圖顯示解決方案。如何使用iOS在故事板上創建ImageView中心?
回答
其相當容易..
1.place所述的UIImageView居中
然後將下面的約束添加
1.centre水平於視圖& &中心垂直於視圖
2.設置長寬比
中心水平,垂直居中,寬高比設置這三年你會得到...
或者'而不是'長寬比'只需添加圖像,'imageView'將獲得圖像的大小。 –
不,它不工作。顯示紅色標記,如果我清除了錯誤,它顯示不正確。@ Kishore! – android
我已更新我的答案,請檢查它.... –
如果你想設計在iOS的通用應用程序,那麼你必須添加的percentage(%)
約束基礎和很少有情況或案件的您不能在Starboard中添加約束條件,但不要擔心,我們可以通過編程來實現。
你有沒有嘗試KVConstraintExtensionsMaster
庫來應用我已經實現的約束。該庫具有方法,該方法將update
,apply
,access
和remove
那些被施加由Programmatically
或從Interface Builder(StoryBoard/xib)
任一所施加的約束。
編程方式imageView顯示所有iPhone和iPad的中心。
- (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步。拖放imageView並將其放置在ViewController的視圖中。
第2步。現在在Container中添加約束水平中心,並在容器中添加垂直中心。
第3步。添加限制等寬和等高。
第4步。現在更新等寬度約束和等高的乘數。
- 1. 無法使用約束中心故事板上的兩個視圖中心 - iOS
- 2. 如何(使用故事板)在iPhone中創建JSON解析器?
- 3. 如何在iOS 7上使用通用故事板的popover segues?
- 4. PFTableViewCell imageView是零(使用故事板)
- 5. 如何在團隊使用git的iOS故事板上工作?
- 6. iOS:我通過適合imageView在故事板中存在問題。
- 7. iOS故事板
- 8. 如何在iOS中的故事板中使用AutoLayout?
- 9. 在WPF中創建故事板?
- 10. 在故事板中創建UIScrollView
- 11. 如何在故事板中使用UIPageViewController?
- 12. 如何在故事板中使用NSAlert
- 13. 創建故事板Xcode 6
- 14. iOS - 在故事板中創建的UILabel不能正確動畫
- 15. 如何使用故事板
- 16. 如何在iOS中使用多個部分組織故事板?
- 17. 故事板如何在iOS 5中使用?
- 18. iOS:使用表格視圖在故事板上使用BeeFramework
- 19. iOS:故事板Segue
- 20. 故事板iOS MBProgressHUD
- 21. 如何使用通用故事板在xcode 6中創建7.1應用程序?
- 22. 故事板中的ios lazytableimages
- 23. 故事板imageview在tableview單元格
- 24. 使用故事板在swift中創建自定義TableViewCell
- 25. 如何在設置應用程序中使用故事板創建表格
- 26. 如何停止在xcode中創建故事板的過程?
- 27. 如何在故事板xcode中創建登錄屏幕
- 28. 故事板 - 在故事板中爲同一個ViewController創建多個視圖
- 29. iOS - 用代碼或故事板設計器創建視圖?
- 30. ios - tabbarcontroller內的splitviewcontroller使用故事板
請參閱[如何在故事板中居中查看](http:// stackoverflow。com/a/28446317/3681880) – Suragch