zoukankan      html  css  js  c++  java
  • Button 自动换行

    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 200, self.view.frame.size.width, 300)];

        view.backgroundColor=[UIColor grayColor];

        [self.view addSubview:view];

        NSMutableArray *array=[[NSMutableArray alloc]initWithObjects:@"园园",@"园园",@"蛋蛋园园",@"啊啊啊啊",@"拉",@"呀呀呀啊呀啊呀呀", nil];

        

        int i=0;

        CGFloat btnH=30;

        CGFloat yOffset=10;

        CGFloat xOffset=15;

        for (NSString *string in array) {

          

            CGRect rect = [string boundingRectWithSize:CGSizeMake(MAXFLOAT, btnH) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17] } context:nil];

            

            CGFloat w = rect.size.width+10;

            NSLog(@"%f",yOffset+w);

            if (xOffset+w>self.view.frame.size.width-20) {

                xOffset=10;

                yOffset+=(btnH+15);

            }

            UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];

            button.titleLabel.font=[UIFont systemFontOfSize:17];

            [button setTitle:string forState:(UIControlStateNormal)];

            [button setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];

            //自己 加  Button的点击 事件 

            [button setBackgroundColor:[UIColor whiteColor]];

            button.layer.cornerRadius=5;

            button.clipsToBounds=YES;

            button.tag=1000+i;

            button.frame = CGRectMake(xOffset, yOffset, w, btnH);

            [view addSubview:button];

             xOffset+=(w+10);

             ++i;

        }

  • 相关阅读:
    HTML_表单
    HTML_列表、表格与媒体元素
    HTML_HTML5基础
    使用java理解程序逻辑 试题分析
    字符串
    带参数的方法
    人机猜拳
    类的无参方法
    类和对象
    vue cli+axios踩坑记录+拦截器使用,代理跨域proxy(更新)
  • 原文地址:https://www.cnblogs.com/106dapeng/p/4707524.html
Copyright © 2011-2022 走看看