UILabel
{uilabel* lb =[[uilabel Alloc]initwithframe:cgrectzero];Lb. Autoresizingmask=uiviewautoresizingflexiblewidth;_lbemptyinfo=lb;Lb. Frame=cgrectmake ( -, -, -, -);Lb. TextColor=colorrgb (0x1e1e1e);Lb. TextAlignment=nstextalignmentleft;Lb. BackgroundColor=[uicolor Clearcolor];Lb. Font=[uifont systemfontofsize: A];Lb. Text[Email protected]"No information about the company has been released.";[Self. ViewADDSUBVIEW:LB];}
UIButton
{UIButton* BT =[UIButtonButtonwithtype:uibuttontypecustom]; Bt. Autoresizingmask=uiviewautoresizingflexiblewidth; [BT setbackgroundimage:[[UIImageimagenamed:@"[email protected]"] Resizableimagewithcapinsets:uiedgeinsetsmake (5,5,5,5)] [forstate:uicontrolstatenormal]; _BTEMPTYCREATE=BT; Bt. Frame=cgrectmake ( -, -, -, -); [BT AddTarget: SelfAction@selector(FORWARDCREATEPOSTVC:) forcontrolevents:uicontroleventtouchupinside]; Bt. BackgroundColor=[UicolorClearcolor]; Bt. Titlelabel. Font=[UifontSystemfontofsize: A]; [BT settitle:@"Publish Now"Forstate:uicontrolstatenormal]; [BT settitlecolor:[UicolorWhitecolor] Forstate:uicontrolstatenormal]; [ Self. ViewADDSUBVIEW:BT]; }
UIView
{ UIView* v=[UIView new]; v.frame=CGRectMake(10010010030); v.autoresizingMask=UIViewAutoresizingFlexibleWidth; v.backgroundColor=COLORRGB(0xd1d4d4); [self.view addSubview:v]; }
Uiimageview
{ UIImageView* iv =[UIImageView new]; iv.frame=CGRectMake(003535); iv.autoresizingMask=UIViewAutoresizingFlexibleWidth; iv.backgroundColor=[UIColor clearColor]; iv.image=[UIImage imageNamed:@"search-calendar-icon"]; [self.view addSubview:iv]; }
UITableView
{uitableview* Tb=[[uitableview alloc]initwithframe:self. View. Bounds];Self. Tbitems=tb;Tb. Tablefooterview=[uiview New];Tb. Autoresizingmask=uiviewautoresizingflexiblewidth| Uiviewautoresizingflexibleheight;Tb. Separatorcolor=colorrgb (0xd6d6d6);Tb. Separatorstyle=uitableviewcellseparatorstylenone;Tb. Delegate=self;Tb. DataSource=self;Tb. BackgroundColor=main_section_bg_color;[Self. ViewADDSUBVIEW:TB];}
Uitextview
{uitextview* Tv=[[uitextview Alloc]initwithframe:cgrectzero];Tv. Frame=cgrectmake (Ten,Ten, -, -);Tv. Tag=tag_cell_tv_note;Tv. TextColor=colorrgb (0x606565);Tv. TextAlignment=nstextalignmentright;Tv. BackgroundColor=[uicolor Clearcolor];Tv. Font=[uifont systemfontofsize: A];[Cell. ContentviewADDSUBVIEW:TV];}
Uiswitch
{uiswitch* Sw=[[uiswitch Alloc]initwithframe:cgrectzero];Sw. Frame=cgrectmake (cell. Frame. Size. Width- --Ten, ( $- -)/2, -, -);Sw. Autoresizingmask=uiviewautoresizingflexiblerightmargin;[SW addtarget:self Action: @selector (handlerswitchevent:) forcontrolevents:uicontroleventvaluechanged];Sw. Tag=tag_cell_sw_switch;Sw. Ontintcolor=main_color_2;[Cell. ContentviewADDSUBVIEW:SW];}
UITableViewCell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; if (!cell) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; cell.selectionStyle=UITableViewCellSelectionStyleNone; }
Uitextfield
{uitextfield* Tf=[[uitextfield Alloc]initwithframe:cgrectzero];Tf. Frame=cgrectmake ( the, -, cell. Frame. Size. Width- the-Ten, the);Tf. Tag=tag_cell_tf_value;[TF addtarget:self Action: @selector (Textfielddidchange:) forcontrolevents:uicontroleventeditingchanged];Tf. BorderStyle=uitextborderstylenone;Tf. TextColor=colorrgb (0x787c7c);Tf. TextAlignment=nstextalignmentright;Tf. BackgroundColor=[uicolor Clearcolor];Tf. Font=[uifont systemfontofsize: -];[Cell. ContentviewADDSUBVIEW:TF];}
Eytagview
{//tag flow eytagview* Tag=[[eytagview Alloc]initwithframe:cgrectzero];Tag. Frame=cgrectmake ( -,( $- -)/2, screen_width- -- -, -);Tag. Tag=tag_header_v_location_flow;Tag. Type=eytagview_type_flow;[Appdelegate Configeytagviewlocationflowstyle:tag];Tag. NumberOfLines=1;Tag. Delegate=self;[Appdelegate Configeytagviewstyle:tag];[_vtableheader Addsubview:tag];}
Layoutuilabel size ignores linenumber, gets the largest size
{uilabel* lb= (id) [_vtableheader viewwithtag:tag_header_lb_remark];Lb. BackgroundColor=test_color_red;Cgsize maximumlabelsize = cgsizemake (LB. Frame. Size. Width, +);Nsdictionary *attributesdictionary = [Nsdictionary dictionarywithobjectsandkeys:lb. Font, Nsfontattributename,nil];nsmutableattributedstring *string = [[Nsmutableattributedstring alloc] initwithstring:lb. TextAttributes:attributesdictionary];CGRect newframe = [string Boundingrectwithsize:maximumlabelsize options:nsstringdrawinguseslinefragmentorigin Context:nil];Change_frame_heigth (LB, newframe. Size. Height);Change_frame_y (LB, cgrectgetmaxy ([_vtableheader Viewwithtag:tag_header_v_location_flow]. Frame)+8) }
When linenumber>1, get size
{ UILabel* lb=(id)_lbSignature; CGSize maximumLabelSize = CGSizeMake(lb.frame.size.width,1000); CGSize newSize =[lb sizeThatFits:maximumLabelSize]; CHANGE_FRAME_HEIGHT(lb, newSize.height) }
{UILabel* Lb= (ID) [_vtableheader Viewwithtag:tag_header_lb_name];cgsizeMaximumlabelsize = Cgsizemake ( +Lb. Frame. Size. Height);nsdictionary*attributesdictionary = [nsdictionaryDictionarywithobjectsandkeys:lb. Font, Nsfontattributename,Nil]; nsmutableattributedstring *string = [[Nsmutableattributedstring alloc] initwithstring:lb. TextAttributes:attributesdictionary];CGRectNewframe = [string boundingrectwithsize:maximumlabelsize options:nsstringdrawinguseslinefragmentorigin context:Nil]; Change_frame_width (LB, newframe. Size. Width); }
Tttattributedlabel size
{tttattributedlabel* lb= (ID) [_vtableheader viewWithTag:TAG_ Header_lb_remark] Lb.backgroundcolor =test_color_red Cgsize maximumlabelsize = cgsizemake (Lb.frame .size .width , 1000 ) Cgsize newsize= [lb sizethatfits:maximumlabelsize] Change_frame_heigth (LB, newsize.height ) ; Change_frame_y (LB, cgrectgetmaxy ([_vtableheader Viewwithtag:tag_header_v_location_flow] .frame ) +8 )}
{uilabel* lb= (id) [_vtableheader viewwithtag:tag_header_lb_browse_count];Cgsize maximumlabelsize = Cgsizemake ( +Lb. Frame. Size. Height);Nsdictionary *attributesdictionary = [Nsdictionary dictionarywithobjectsandkeys:lb. Font, Nsfontattributename,nil];nsmutableattributedstring *string = [[Nsmutableattributedstring alloc] initwithstring:lb. TextAttributes:attributesdictionary];CGRect newframe = [string Boundingrectwithsize:maximumlabelsize options:nsstringdrawinguseslinefragmentorigin Context:nil];Change_frame_width (LB, newframe. Size. Width+2);//here:text is clip, why??change_frame_x (LB, Cgrectgetminx ([_vtableheader Viewwithtag:tag_header_iv_comment_icon]. Frame)-LB. Frame. Size. Width-8);Change_frame_y (LB, cgrectgetminy ([_vtableheader Viewwithtag:tag_header_lb_comment_count]. Frame)}} {uiview* v= (id) [_vtableheader viewwithtag:tag_header_iv_read_icon];Change_frame_x (V, Cgrectgetminx ([_vtableheader Viewwithtag:tag_header_lb_browse_count]. Frame)-V. Frame. Size. Width-3) change_frame_y (V, cgrectgetminy ([_vtableheader Viewwithtag:tag_header_lb_comment_count]. Frame)) }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
IOS UI CodeSnippet