#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatPic];
    
}

- (void)creatPic
{
    for (int i=0; i<3; i++) {
        
        //创建button
        UIButton *btn1=[[UIButton alloc] init];
        
        btn1.frame=CGRectMake(50, 50+i*180, 300, 150);
        
        [self.view addSubview:btn1];
        
        btn1.backgroundColor=[UIColor cyanColor];
        
        //创建UIImageView
        UIImageView *iv1=[[UIImageView alloc] init];
        
        iv1.frame=CGRectMake(20, 20, 180, 110);
        
        [btn1 addSubview:iv1];
        
        iv1.backgroundColor=[UIColor blueColor];
        
        iv1.image=[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i]];
        
        iv1.contentMode=UIViewContentModeScaleToFill;
        
        iv1.alpha=0.8;
        
        //创建按钮
        UILabel *label1=[[UILabel alloc] init];
        UILabel *label2=[[UILabel alloc] init];
        
        label1.text=@"名字";
        label2.text=@"详情";
        
        label1.textAlignment=NSTextAlignmentCenter;
        label2.textAlignment=NSTextAlignmentCenter;
        
        label1.textColor=[UIColor blackColor];
        label2.textColor=[UIColor blackColor];
        
        label1.frame=CGRectMake(270, 120+i*180, 60, 25);
        label2.frame=CGRectMake(270, 160+i*180, 60, 25);
        
        label1.backgroundColor=[UIColor grayColor];
        label2.backgroundColor=[UIColor greenColor];
        
        [self.view addSubview:label1];
        [self.view addSubview:label2];
     }
}

//这是.jpg图片

这里在一个循环三次的函数中创建了button,imageView等

//这是最后的运行结果

在button中加入一个view图片的更多相关文章

  1. IOS中封装一个View的思路

    一.封装一个View的思路 1.将View内部的业务逻辑(显示内容)封装到View中 2.一般情况下,View的位置应该由父控件来决定,也就是位置不应该固定死在View内部 3.至于View的宽高,根 ...

  2. Umbraco -- 在Visual Studio中新建一个View 如何在Umbraco back office 中显示出来

    在使用Umbraco中的过程中,遇到一个问题. 我在项目中(Visual Studio),添加了一个View---Test.cshtml. 然后进入到该Umbraco项目的back office, 在 ...

  3. python 编程中的一个关于图片的库 imageio (读取照片RGB内容,转换照片格式)

    最近在看机器学习方面的东西,经常遇到需要把某个类型的照片中 RGB 内容读取出来, 在python中照片显示用matplotlib就可以做到,但是导入不同格式的照片,保持出不同格式的照片numpy, ...

  4. android中的一个圆角图片

    RoundedImageView A fast ImageView (and Drawable) that supports rounded corners (and ovals or circles ...

  5. 让android系统中任意一个view变成进度条

    1.效果 2.进度条背景drawable文件 结束后可以恢复原背景. <?xml version="1.0" encoding="utf-8"?> ...

  6. Android中显示gif动态图片

    在android中显示一个静态图片比如png jpg等等都很方便,但是如果要显示一个gif 动态图片就需要进行一些处理. 本文是采用自定义view 然后进行重新onDraw方法来实现 首先自定义Vie ...

  7. 在iOS中实现一个简单的画板App

    在这个随笔中,我们要为iPhone实现一个简单的画板App. 首先需要指出的是,这个demo中使用QuarzCore进行绘画,而不是OpenGL.这两个都可以实现类似的功能,区别是OpenGL更快,但 ...

  8. vue项目中编写一个图片预览的公用组件

    今天产品提出了一个查看影像的功能需求. 在查看单据的列表中,有一列是影像字段,一开始根据单据号调用接口查看是否有图片附件,如果有则弹出一个全屏的弹出层,如果没有给出提示.而且,从列表进入详情之后,附件 ...

  9. 在Android中动画移动一个View的位置,采用Scroller类实现Android动画之 View移动

    在Android中动画移动一个View的位置,采用Scroller类实现 今天说最近自己遇到的一个问题,就是要用动画效果来移动一个VIew的位置. 这个具体的情况是,需要做一个SlidingMenu的 ...

随机推荐

  1. Linux下Vim工具常用命令

    原文地址: http://www.cnblogs.com/lizhenghn/p/3675011.html 在linux下做开发,甚至是只做管理维护工作,也少不了Vim的使用.作为一个新手,我也是刚刚 ...

  2. MATLAB新手教程

    MATLAB新手教程   .MATLAB的基本知识 1-1.基本运算与函数    在MATLAB下进行基本数学运算,仅仅需将运算式直接打入提示号(>>)之後,并按入Enter键就可以.比如 ...

  3. 2015南阳CCPC F - The Battle of Guandu 多源多汇最短路

    The Battle of Guandu Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description In the year of 200, t ...

  4. Delphi 7连接MySql 5.5.15

    原文:http://blog.csdn.net/akof1314/article/details/6822902/ 网上有很多关于Delphi连接MySql数据库的文章,在这里,我只记录下自己测试过的 ...

  5. 怎样拷贝整个目录并且忽略部分文件及目录(包括windows)

    http://www.dewen.org/q/2150 rsync -a --exclude dir1 --exclude dir2 ... source target

  6. iOS开发——网络编程Swift篇&(三)同步Get方式

    同步Get方式 // MARK: - 同步Get方式 func synchronousGet() { //创建NSURL对象 var url:NSURL! = NSURL(string: " ...

  7. leetcode -- Largest Rectangle in Histogram TODO O(N)

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  8. Step-by-Step XML Free Spring MVC 3 Configuration--reference

    The release of Spring 2.5 reduce the burden of XML by introduction annotation based configuration, b ...

  9. 如何使用Linux命令dhclient

    如何使用Linux命令 dhclient The Internet Systems Consortium DHCP Client, dhclient, provides a means for con ...

  10. python(3)-深浅拷贝

    import copy copy.copy()    浅拷贝 copy.deepcopy()   深拷贝 >>> import copy >>> a1 = 123 ...