简体   繁体   English

如何在iPhone5和iPhone6上更改UIImageView的大小?

[英]How to change size of UIImageView on iphone5 & iphone6?

I have an image to display in my app. 我有一张要显示在我的应用中的图片。 I want to set the size of the image on iPhone6 to 169pt & on iPhone5 set it 120pt. 我想将iPhone6上的图像大小设置为169pt,而在iPhone5上将其设置为120pt。 I know there is a size class on iOS8. 我知道iOS8上有一个size类。 But how can I set different sizes for different iPhones on it. 但是,如何在其上为不同的iPhone设置不同的尺寸。 I can only distinguish between iPad & iphone portrait/landscape in size classes & can not distinguish iPhone 5 from iPhone6 我只能在大小级别上区分iPad和iPhone肖像/风景,不能区分iPhone 5和iPhone6

Have you considered using AutoLayout? 您是否考虑过使用自动版式? It's a constraint-resolver based layout system that will make your views responsive, and it's Apple's preferred method starting in iOS7. 这是一个基于约束解析器的布局系统,可使您的视图响应,并且它是iOS7中Apple的首选方法。 Docs are here: 文件在这里:

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html

And a great tutorial here: 还有一个很棒的教程:

http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1 http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1

AutoLayout is a far more robust method for keeping your views responsive even as Apple adds new UI idioms and sizes (like the Apple Watch). 即使Apple添加了新的UI习惯用法和大小(例如Apple Watch),“自动布局”也是一种使视图保持响应速度更快的健壮方法。 Imperative sizing code will quickly become fragile as the number of sizes to support increases. 随着要支持的大小数量的增加,命令式大小调整代码将很快变得脆弱。

Just pulled this from one of my projects. 刚刚从我的一个项目中撤出了这个。 It shows the logic I use for working out what device the user is using 它显示了我用于确定用户使用哪种设备的逻辑

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0)
#define IS_IPHONE_6PLUS (IS_IPHONE && [[UIScreen mainScreen] nativeScale] == 3.0f)
#define IS_IPHONE_6_PLUS (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 736.0)
#define IS_RETINA ([[UIScreen mainScreen] scale] == 2.0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM