登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

查看: 31|回复: 6

iOS UI CodeSnippet,ios ui控件

[复制链接]

210

主题

210

帖子

1902

金钱

手工艺人

发表于 6 天前 | 显示全部楼层 |阅读模式

        UILabel
[Java] 查看源文件 复制代码
 {
        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=#还没有发布任何约伴信息哦!;
        [self.view addSubview:lb];

    }


UIButton
[Java] 查看源文件 复制代码

    {
        UIButton* bt =[UIButton buttonWithType:UIButtonTypeCustom];
        bt.autoresizingMask=UIViewAutoresizingFlexibleWidth;
        [bt setBackgroundImage:[[UIImage imageNamed:#yb_bt_bg_1_nor#2x] resizableImageWithCapInsets: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:#立即发布 forState:UIControlStateNormal];
        [bt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.view addSubview:bt];

    }


UIView
[Java] 查看源文件 复制代码
{
            UIView* v=[UIView new];
            v.frame=CGRectMake(100, 100, 100, 30);
            v.autoresizingMask=UIViewAutoresizingFlexibleWidth;
            v.backgroundColor=COLORRGB(0xd1d4d4);
            [self.view addSubview:v];

        }

UIImageView
[Java] 查看源文件 复制代码
{
            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
[Java] 查看源文件 复制代码
{
        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
[Java] 查看源文件 复制代码
{
          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
[Java] 查看源文件 复制代码
 {
            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
[Java] 查看源文件 复制代码
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#Cell];
    if (!cell)
    {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#Cell];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }

UITextField
[Java] 查看源文件 复制代码
 {
            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
[Java] 查看源文件 复制代码
{//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];
    }

layout
UILabel size
忽略 linenumber ,得到最大的size
[Java] 查看源文件 复制代码
{
        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)
    }

当linenumber>1时候,得到size
[Java] 查看源文件 复制代码
{
        UILabel* lb=(id)_lbSignature;
        CGSize maximumLabelSize = CGSizeMake(lb.frame.size.width,1000);
         CGSize newSize =[lb sizeThatFits:maximumLabelSize];
        CHANGE_FRAME_HEIGHT(lb, newSize.height)
    }

[Java] 查看源文件 复制代码
{
        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
[Java] 查看源文件 复制代码
{
        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)
    }

[Java] 查看源文件 复制代码

  {
        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))
    }

        


                                               

0

主题

6488

帖子

-507

金钱

限制会员

发表于 6 天前 | 显示全部楼层
写的真的很不错

14

主题

6497

帖子

1085

金钱

iOS大神

Rank: 6Rank: 6

发表于 6 天前 | 显示全部楼层
感谢分享,楼主V5~

18

主题

6516

帖子

1753

金钱

iOS大神

Rank: 6Rank: 6

发表于 6 天前 | 显示全部楼层
我是来学习的

23

主题

6521

帖子

1064

金钱

iOS大神

Rank: 6Rank: 6

分享大神

发表于 6 天前 | 显示全部楼层
帮帮顶顶!!

18

主题

6498

帖子

1863

金钱

iOS大神

Rank: 6Rank: 6

发表于 6 天前 | 显示全部楼层
感谢大神分享,必须顶!

3

主题

6505

帖子

424

金钱

攻城狮

Rank: 3Rank: 3

发表于 6 天前 | 显示全部楼层
内容很好,棒棒哒
*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

关闭

每日头条

通过邮件订阅最新 Code4App 信息
上一条 /4 下一条

广告投放| Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

快速回复 返回顶部 返回列表