//UIButton的基本属性

_btn = [UIButton buttonWithType:UIButtonTypeCustom];

_btn.frame = CGRectMake(0, 200, 90, 90);

_btn.backgroundColor = [UIColor redColor];

_btn.tag = 100;

[_btn setTitle:@"我爱你" forState:UIControlStateNormal ];

[_btn setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal ];

[_btn addTarget:self action:@selector(btnClick:) forControlEvents: UIControlEventTouchUpInside];

//设置button的圆角、边框

_btn.layer.cornerRadius  =10;

_btn.layer.borderWidth = 5.0;

_btn.layer.borderColor = [UIColor blueColor].CGColor;

//设置button标签文字的颜色

[_btn setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];

//标签文字的字体

[_btn.titleLabel setFont:[UIFont systemFontOfSize:28]];

_btn.tag = 101;

[self.view addSubview:_btn];

UIButton*bnt = [UIButton buttonWithType:UIButtonTypeSystem];

bnt.frame = CGRectMake(60, 300, 80, 80);

//button的颜色

bnt.backgroundColor = [UIColor grayColor];

bnt.layer.cornerRadius = 40;

bnt.layer.borderColor = [UIColor redColor].CGColor;

bnt.layer.borderWidth  = 5.0;

[bnt setTitle:@"mapanguan" forState:UIControlStateNormal ];

[bnt setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal ];

[bnt.titleLabel setFont:[UIFont systemFontOfSize:20]];

bnt.tag = 102;

//添加点击事件

[bnt addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDragOutside];

[self.view addSubview:bnt];

}

-(void)btnClick:(UIButton*)btn{

if (101 == _btn.tag) {

NSLog(@"按钮被点击了");

//点击显示随机颜色(需先定义)

int index = arc4random()%[self.colors count];

self.btn.backgroundColor = self.colors[index];

}

}

iOS笔记之UIKit_UIButton的更多相关文章

  1. 荼菜的iOS笔记--UIView的几个Block动画

    前言:我的第一篇文章荼菜的iOS笔记–Core Animation 核心动画算是比较详细讲了核心动画的用法,但是如你上篇看到的,有时我们只是想实现一些很小的动画,这时再用coreAnimation就会 ...

  2. IOS笔记 1

    < ![CDATA[ 笔记 UIWindows 与UIView的关系iOS的坐标系统视图层次结构视图坐标(Frame和Bounds区别)UIView的常用属性和方法坐标系统的变换UIView内容 ...

  3. 【转】iOS笔记-自定义控件(OC)

    原文网址:http://www.jianshu.com/p/f23862eb7b8a 导读: iOS开发中,很多时候系统提供的控件并不能很好的满足我们的需求,因此,自定义控件便成为搭建UI界面中必不可 ...

  4. iOS笔记———数据存储

    应用沙盒:应用文件系统的根目录,每个应用都有独自的沙盒相互:在xcode中可以用NSHomeDirectory()函数,打印当前应用的沙盒根路径. 应用程序包:包含了所有资源文件和执行文件; * Do ...

  5. Xamarin开发IOS笔记:切换输入法时输入框被遮住

    在进行IOS开发的过程中,出现类似微信朋友圈的交互界面,当用户遇到感兴趣的内容可以进行评论.为了方便评论输入,当出现评论输入框的时候自动将评论输入框移动至键盘的上方,这样方便边输入边查看. 当用户隐藏 ...

  6. 【IOS笔记】Delegation

    Delegation Delegation is a simple and powerful pattern in which one object in a program acts on beha ...

  7. 【IOS笔记】Event Delivery: The Responder Chain

    Event Delivery: The Responder Chain  事件分发--响应链 When you design your app, it’s likely that you want t ...

  8. 【IOS笔记】Gesture Recognizers

    Gesture Recognizers Gesture recognizers convert low-level event handling code into higher-level acti ...

  9. 【IOS笔记】About Events in iOS

    About Events in iOS Users manipulate their iOS devices in a number of ways, such as touching the scr ...

随机推荐

  1. Oracle Linux下数据库操作的相关问题

    1.su - oracle 切换到oracle用户 lsnrctl status 查看数据库监听状态 lsnrctl start 打开数据库监听 2.Connected to an idle inst ...

  2. 关于发件人地址会自动增加BATV及prvs的问题处理方法

    问题描述: 发现Exchange 2010往外发邮件时,有些用户的发件人地址会自动增加BATV= 及 prvs=绪如,这些的特定字符,变成型如prvs=123456=example@example.c ...

  3. 大牛的距离(笑cry)精简算法

    在一条数轴上有N头牛在不同的位置上,每头牛都计算到其它各头牛的距离.求这n*(n-1)个距离的总和.1<= N <= 10000.每头牛所在位置是一个范围在0到1,000,000,000之 ...

  4. kafka配置简要描述

    配置文件在config/server.properties 下面的一些配置可能是你需要进行修改的. 这里为官方提供配置文件解释:https://kafka.apache.org/08/configur ...

  5. UI设计教程学习分享:APP布局

    一.宫格布局 这种APP信息布局方式也是我们目前最常见的一种方式,也是符合用户习惯和黄金比例的设计方式,最知名的就是锤子手机的界面设计.锤子手机界面设计欣赏知名的APP设计采用的九宫格.六宫格等方式布 ...

  6. CreateToolhelp32Snapshot 以及 EnumProcesses

    RT,请教如何获得Windows任务管理器中所显示的进程列表. CreateToolhelp32Snapshot 以及 EnumProcesses 这些方法我都试过了,但是这两种方法得到的结果和任务管 ...

  7. Why Linux Doesn’t Need Defragmenting

    If you’re a Linux user, you’ve probably heard that you don’t need to defragment your Linux file syst ...

  8. How to execute sudo command in remote host via SSH

    Question: I have an interactive shell script, that at one place needs to ssh to another machine (Ubu ...

  9. django 静态文件

    django中的静态文件,如图片,css样式jquery等等 在url最下面加上 from django.conf.urls.static import staticfrom django.conf ...

  10. 神奇的幻方(NOIP2015)

    先给题目链接:神奇的幻方 太水了这题,直接模拟就行,直接贴代码. #include<bits/stdc++.h> using namespace std; int main(){ int ...