Refer to multi-screen adaptation
So far, there are four of iphone screen sizes:
3.5 (Inch): 1/3g/3gs/4/4s
4.0 (inch): 5/5s/5c
4.7 (Inch): 6
5.5 (Inch): 6Plus
Take a look at the screen aspect ratio of iphone4~6 (+):
IPhone4 (s): Resolution 960*640, Aspect ratio 1.5
IPhone5 (s): Resolution 1136*640, Aspect ratio 1.775
IPhone6: Resolution 1334*750, Aspect ratio 1.779
iphone6+: Resolution 1920*1080, Aspect ratio 1.778
It can be roughly assumed that the aspect ratio of iPhone5 (s), 6 (+) is consistent (16:9), which can be scaled proportionally. Therefore, you can fit by width:
Fitscreenwidth= width* (screen_width/320)
In this way, a total of IPHONE3/4/5, 6, 6+ three sets of width, in IPhone6, 6+ will be scaled horizontally, that is, we want to adapt to the width, height, font size (if the Android screen fit is hell, the current look at the iphone screen fit is still very good)
The idea of adapting to match
Now the product design draft has to IPHONE5 as the benchmark, but also to IPhone6 as the benchmark, in fact, not much impact, because IPhone5, 6, 6P screen size is almost the same, so the size of the iPhone5 as a benchmark, the appropriate method is as follows:
#define kscreenwidthratio (kscreenwidth/320.0)#define kscreenheightratio (Kscreenheight/ 568.0)#define adaptedwidthvalue (x) (Ceilf ((x) * kscreenwidthratio))#define Adaptedheightvalue (x) (Ceilf ((x) * kscreenheightratio))
In fact, the calculation of a proportion, and then IPhone6, 6P and other than amplification, so that the IPhone5, 6, 6P screen visual effect on the same.
Control size thinking is done, but only the control and other proportional stretching, the content of which also to adapt, such as Uilabel font size adaptation, in fact, is also very simple:
#define kuhsystemfontwithsize (r) [Uifont fontwithname:kulsystemfont Size: (Adaptedwidthvalue (R))]
Practice
Once you have the idea, take a look at the effect and first look at the final goal:
Top
UI adaptation for iOS development ~iphone6 and iphone6p
Demo Introduction:
1, the use of TableView display data, wherein the TableView Headerview is a rolling advertisement, the overall UI layout using relative layout (AutoLayout);
2, AutoLayout uses the code realization Way, with the third party library masonry;
3, Headerview the implementation of the rolling ads is the help of third-party library Sdcyclescrollview;
4, Picture download with third-party library sdwebimage;
5, UITableViewCell Adaptive height with the third-party library Uitableview+fdtemplatelayoutcell implementation.
New Project
After using Xcode to create a new project, use Cocopods, which modifies podfile, because of the use of many third parties:
Platform:ios, '7.0' pod ' masonry ' pod ' sdcyclescrollview ' pod ' uitableview+ Fdtemplatelayoutcell ' pod ' sdwebimage '
Implement TableView
1. Create a TableView, named Newslistview:
@property (nonatomic, strong) UITableView *newslistview;
Concrete implementation does not say, introduce the layout of TableView, here TableView stained with Viewcontroller view:
[Self.newslistview mas_makeconstraints:^ (Masconstraintmaker * make) {make.edges.equalTo (Self.view);}];
2. Realize Tableviewheader
- (void) Loadtableviewheaderview {Sdcyclescrollview* Cyclescrollview = [Sdcyclescrollview cyclescrollviewwithframe:cgrectmake (0,0, Kscreenwidth, Adaptedheightvalue (sdcyclescrollviewheight)) Imageurlstringsgroup:nil];//Analog Network Latency ScenariosCyclescrollview.pagecontrolaliment =sdcyclescrollviewpagecontolalimentright; Cyclescrollview.Delegate=Self ; Cyclescrollview.showpagecontrol=YES; Cyclescrollview.pagecontrolstyle=sdcyclescrollviewpagecontolstyleanimated; cyclescrollview.pagecontrolaliment=Sdcyclescrollviewpagecontolalimentcenter; Cyclescrollview.dotcolor= [Uicolor Whitecolor];//Custom Paging control small round colorCyclescrollview.placeholderimage =[UIImage imagenamed:@ "Detail_top"]; [Self.view Addsubview:cyclescrollview];cyclescrollview.imageurlstringsgroup= [Self.datadictionary Valueforkey:@"advertisement"];self.newslistview.tableheaderview=Cyclescrollview;}
Using Adaptedheightvalue (Sdcyclescrollviewheight) to fit the screen size, the tableviewheader height of the 4/4s device is smaller, The Tableviewheader height of 6 and 6P is bigger, because we are the product design draft that has been implemented for reference of 5 generation equipment.
3. Realize Tableviewcell
#defineUi_debug 0#defineUlappearancefontsizemiddle 13#defineUlappearancefontsizesmall 12NSString*ConstNewslistcellidentifier =@"Newslistcellidentifier";Static ConstCGFloat Ulnewslistcellnewsimageviewmarginleft =10.0;Static ConstCGFloat ulnewslistcellnewsimageviewwidth =100.0;Static ConstCGFloat ulnewslistcellnewsimageviewheight =80.0;Static ConstCGFloat ulnewslistcelltitlelabelmargintop =10.0;Static ConstCGFloat Ulnewslistcelltitlelabelmarginleft =10.0;Static ConstCGFloat ulnewslistcelltitlelabelmarginright =10.0;Static ConstCGFloat ulnewslistcelltitlelabelheight =20.0;Static ConstCGFloat ulnewslistcellcontentlabelmargintop =10.0;Static ConstCGFloat Ulnewslistcellcontentlabelmarginbottom =10.0;Static ConstCGFloat Ulnewslistcelllineviewmarginleft =10.0;Static ConstCGFloat ulnewslistcelllineviewmarginright =10.0;Static ConstCGFloat ulnewslistcelllineviewheight =0.5; @interface Newslistcell () @property (nonatomic, strong) Uiimageview*Newsimageview, @property (nonatomic, strong) UILabel*Titlelabel, @property (nonatomic, strong) UILabel*Contentlabel, @property (nonatomic, strong) UIView*Lineview, @end @implementation Newslistcell-(Instancetype) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) Reuseidentifier {if(self =[Super Initwithstyle:style Reuseidentifier:reuseidentifier]) {#ifUi_debugSelf.contentView.backgroundColor=[Uicolor Redcolor];#endif[Self.contentview AddSubview:self.newsImageView]; [Self.contentview AddSubview:self.titleLabel]; [Self.contentview AddSubview:self.contentLabel]; [Self.contentview AddSubview:self.lineView]; [Self makeconstraintsubviews]; } returnSelf ;}- (void) makeconstraintsubviews {[Self.newsimageview mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.left.equalTo (self.contentView.mas_left). Offset (Adaptedwidthvalue (ulnewslistcellnewsimageviewmarginleft)) ; Make.size.mas_equalTo (Cgsizemake (Adaptedwidthvalue (ulnewslistcellnewsimageviewwidth), Adaptedheightvalue ( (ulnewslistcellnewsimageviewheight))); Make.centerY.equalTo (Self.contentView.mas_centerY); }]; [Self.titlelabel mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.top.equalTo (self.contentView.mas_top). Offset (Adaptedheightvalue (ulnewslistcelltitlelabelmargintop)); Make.left.equalTo (self.newsImageView.mas_right). Offset (Adaptedwidthvalue (ulnewslistcelltitlelabelmarginleft)); Make.right.equalTo (self.contentView.mas_right). Offset (-Adaptedwidthvalue (ulnewslistcelltitlelabelmarginright)); Make.height.mas_equalTo (Adaptedheightvalue (ulnewslistcelltitlelabelheight));//Make.bottom.equalTo (self.contentLabel.mas_top). Offset (-adaptedheightvalue ( Ulnewslistcellcontentlabelmargintop)); }]; [Self.contentlabel mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.left.right.equalTo (Self.titlelabel); Make.top.equalTo (Self.titleLabel.mas_bottom). Offset (Adaptedheightvalue (ulnewslistcellcontentlabelmargintop)); Make.bottom.equalTo (Self.lineView.mas_bottom). Offset (-Adaptedheightvalue (Ulnewslistcellcontentlabelmarginbottom)); }]; [Self.lineview mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.bottom.equalTo (Self.contentView.mas_bottom). Offset (-ulnewslistcelllineviewheight); Make.left.equalTo (self.contentView.mas_left). Offset (Adaptedwidthvalue (ulnewslistcelllineviewmarginleft)); Make.right.equalTo (self.contentView.mas_right). Offset (-Adaptedwidthvalue (ulnewslistcelllineviewmarginright)); Make.height.mas_equalTo (Ulnewslistcelllineviewheight); }];}- (void) Configurewithdata: (News *) News {[Self.newsimageview sd_setimagewithurl:[nsurl URLWithString:news.imageUrl]]; Self.titleLabel.text=News.title; Self.contentLabel.text=news.content;}#pragmamark-getters-(Uiimageview *) Newsimageview {if(!_newsimageview) {_newsimageview=[[Uiimageview alloc] init];#ifUi_debug_newsimageview.backgroundcolor=[Uicolor Greencolor];#endif } return_newsimageview;}-(UILabel *) Titlelabel {if(!_titlelabel) {_titlelabel=[[UILabel alloc] init]; _titlelabel.font=kuhsystemfontwithsize (Ulappearancefontsizemiddle); _titlelabel.textcolor=[Uicolor Blackcolor];#ifUi_debug_titlelabel.backgroundcolor=[Uicolor Lightgraycolor];#endif } return_titlelabel;}-(UILabel *) Contentlabel {if(!_contentlabel) {_contentlabel=[[UILabel alloc] init]; _contentlabel.font=kuhsystemfontwithsize (Ulappearancefontsizesmall); _contentlabel.textcolor=[Uicolor Graycolor]; _contentlabel.numberoflines=0; _contentlabel.linebreakmode=nslinebreakbywordwrapping; _contentlabel.textalignment=Nstextalignmentleft;#ifUi_debug_contentlabel.backgroundcolor=[Uicolor Browncolor];#endif } return_contentlabel;}-(UIView *) Lineview {if(!_lineview) {_lineview=[[UIView alloc] init]; _lineview.backgroundcolor=[Uicolor Lightgraycolor]; } return_lineview;} @end
IOS screen Adapter (GO)