IOS UI CodeSnippet

Source: Internet
Author: User

IOS UI CodeSnippet
UILabel

{UILabel * lb = [[UILabel alloc] initWithFrame: CGRectZero]; lb. autoresizingMask = UIViewAutoresizingFlexibleWidth; _ lbEmptyInfo = lb; lb. frame = CGRectMake (100,100,100, 14); lb. textColor = COLORRGB (0x1e1e1e); lb. textAlignment = NSTextAlignmentLeft; lb. backgroundColor = [UIColor clearColor]; lb. font = [UIFont systemFontOfSize: 12]; lb. text = @ no companion information has been published !; [Self. view addSubview: lb];}
UIButton
{UIButton * bt = [UIButton buttonWithType: UIButtonTypeCustom]; bt. autoresizingMask = upper; [bt setBackgroundImage: [UIImage imageNamed: @ lower @ 2x] lower: UIEdgeInsetsMake (5, 5, 5, 5)] forState: UIControlStateNormal]; _ btEmptyCreate = bt; bt. frame = CGRectMake (100,100,100, 30); [bt addTarget: self action: @ selector (forwardCreatePostVC :) forControlEvents: UIControlEventTouchUpInside]; bt. backgroundColor = [UIColor clearColor]; bt. titleLabel. font = [UIFont systemFontOfSize: 12]; [bt setTitle: @ release now forState: UIControlStateNormal]; [bt setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal]; [self. view addSubview: bt];}
UIView
{            UIView* v=[UIView new];            v.frame=CGRectMake(100, 100, 100, 30);            v.autoresizingMask=UIViewAutoresizingFlexibleWidth;            v.backgroundColor=COLORRGB(0xd1d4d4);            [self.view addSubview:v];        }
UIImageView
{            UIImageView* iv =[UIImageView new];            iv.frame=CGRectMake(0, 0, 35, 35);            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.view addSubview:tb];    }
UITextView
{          UITextView* tv=[[UITextView alloc]initWithFrame:CGRectZero];            tv.frame=CGRectMake(10, 10, 100, 100);            tv.tag=TAG_CELL_TV_NOTE;            tv.textColor=COLORRGB(0x606565);            tv.textAlignment=NSTextAlignmentRight;            tv.backgroundColor=[UIColor clearColor];            tv.font=[UIFont systemFontOfSize:12];            [cell.contentView addSubview:tv];        }
UISwitch
 {            UISwitch* sw=[[UISwitch alloc]initWithFrame:CGRectZero];            sw.frame=CGRectMake(cell.frame.size.width-33-10, (45-20)/2, 33, 20);            sw.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;            [sw addTarget:self action:@selector(handlerSwitchEvent:) forControlEvents:UIControlEventValueChanged];            sw.tag=TAG_CELL_SW_SWITCH;            sw.onTintColor=MAIN_COLOR_2;            [cell.contentView addSubview: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(80, 16, cell.frame.size.width-80-10, 15);            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:13];            [cell.contentView addSubview:tf];        }
EYTagView
{//tag flow        EYTagView* tag=[[EYTagView alloc]initWithFrame:CGRectZero];        tag.frame=CGRectMake(100,(45-28)/2, SCREEN_WIDTH-100-25, 30);        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 to obtain the maximum size.
{        UILabel* lb=(id)[_vTableHeader viewWithTag:TAG_HEADER_LB_REMARK];        lb.backgroundColor=TEST_COLOR_RED;        CGSize maximumLabelSize = CGSizeMake(lb.frame.size.width,1000);        NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:lb.font,NSFontAttributeName,nil];        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:lb.text attributes: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 is greater than 1, the size is obtained.
{        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];        CGSize maximumLabelSize = CGSizeMake(1000, lb.frame.size.height);        NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:lb.font,NSFontAttributeName,nil];        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:lb.text attributes:attributesDictionary];        CGRect newFrame = [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(1000, lb.frame.size.height);        NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:lb.font,NSFontAttributeName,nil];        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:lb.text attributes: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))    }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.