zoukankan      html  css  js  c++  java
  • ios中布局(推荐一)

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        NSArray *data=@[@"标题一",@"标题二",@"标题三",@"标题四"];
        
        CGRect leftRect,rowRect;
        CGRectDivide(self.view.bounds, &rowRect, &leftRect, 80, CGRectMinYEdge);
        UIView *redView=[[UIView alloc] initWithFrame:rowRect];
        redView.backgroundColor=[UIColor redColor];
        [self.view addSubview:redView];
        [redView release];
        
        CGSize size=CGSizeMake(50, 50);//图片的大小
    
        CGFloat width=rowRect.size.width/data.count;//按钮的宽度和高度
        CGFloat heigh=rowRect.size.height;
        
        CGFloat imagew=(width-size.width)*0.5f;
        CGFloat imageh=(heigh-size.height)*0.5f;
        for (int i=0; i<data.count; i+=1) {
            

        CGRect btnRect=CGRectMake(i*width, 0, width, heigh);

    
    

            leftRect=UIEdgeInsetsInsetRect(btnRect, UIEdgeInsetsMake(imageh-10,imagew, imageh+10, imagew));//设置图片剧中

    
    

            UIImageView *imgview=[[UIImageViewalloc] initWithFrame:leftRect];

    
    

            imgview.image=[UIImage imageNamed:@"icon_weibo"];

    
    

            

    
    

            

    
    

            

    
    

            leftRect=UIEdgeInsetsInsetRect(btnRect, UIEdgeInsetsMake(btnRect.size.height-25, imagew, 5, imagew-10));

    
    

            UILabel *lb=[[UILabelalloc] initWithFrame:leftRect];

    
    

            lb.backgroundColor=[UIColorclearColor];

    
    

            lb.text=data[i];

    
    

            [redView addSubview:lb];

    
    

            [lb release];

    
    

            

    
    

            leftRect=UIEdgeInsetsInsetRect(btnRect, UIEdgeInsetsMake(5, imagew, 5, imagew));

    
    

            UIButton *btn=[[UIButtonalloc] initWithFrame:leftRect];

    
    

            [btn addTarget:selfaction:@selector(click) forControlEvents:UIControlEventTouchUpInside];

    
    

            [redView addSubview:btn];

    
            
            
        }
        
        
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    -(void)click{
        NSLog(@"-->click");
    }
  • 相关阅读:
    Jmeter 将正则表达式提取的参数传给全局(跨线程组使用变量)
    pod的状态分析
    前端 -- html介绍和head标签
    Python ----- 线程和进程
    网络编程 ------ 基础
    面向对象相关操作
    面向对象 --- 进阶篇
    python --- 面向对象
    python的模块和包的详细说明
    常用模块------时间模块 , random模块 ,os模块 , sys模块
  • 原文地址:https://www.cnblogs.com/gcb999/p/3273049.html
Copyright © 2011-2022 走看看