//第一种创建UIButton的方法

//initWhitFrame:

UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(110, 100, 100, 30)];

button.backgroundColor = [UIColor redColor];

button.titleLabel.font = [UIFont systemFontOfSize:19.0];//设置按钮的文字大小

button.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;//设置按钮文字的位置(默认为居中)

button.contentEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);//字体靠左或右时与边缘的距离

[button setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];//设置按钮文字的颜色

[button setTitle:@"LYD" forState:UIControlStateNormal];

[self.window addSubview:button];

[button release];

  //第二种创建按钮的方法

//buttonWithType

UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];

button1.layer.cornerRadius = 10.0;

//UIButtonTypeInfoLight 微件(widget)使用的蓝色小圆圈信息按钮,可以放在任何文字旁边

//UIButtonTypeRoundedRect 圆角矩形

//UIButtonTypeInfoDark  白色背景下使用的深色圆圈信息按钮

//UIButtonTypeContactAdd 圆圈中一个加号的信息按钮

//UIButtonTypeDetailDisclosure 蓝色的披露按钮,可放在任何文字旁

CGRect RECT = CGRectMake(110, 100, 30, 30);

button1.frame = RECT;

/*//button1.selected = YES;

//button1.enabled = NO;

//设置标题,状态正常

[button1 setTitle:@"normal" forState:UIControlStateNormal];

//设置标题,状态高亮

[button1 setTitle:@"highlighted" forState:UIControlStateHighlighted];

//设置标题,状态禁用

[button1 setTitle:@"disabled" forState:UIControlStateDisabled];

//设置标题,状态选中

[button1 setTitle:@"selected" forState:UIControlStateSelected];*/

//设置背景图片

[button1 setBackgroundImage:[UIImage imageNamed:@"button_white"] forState:UIControlStateNormal];

[button1 setBackgroundImage:[UIImage imageNamed:@"button_red"] forState:UIControlStateSelected];

//设置图片

//    [button1 setImage:[UIImage imageNamed:@"button_white"] forState:UIControlStateNormal];

//    [button1 setImage:[UIImage imageNamed:@"button_red"] forState:UIControlStateSelected];

//添加事件

//用户控件之内触摸抬按下时

[button1 addTarget:self action:@selector(touchInSide:) forControlEvents:UIControlEventTouchUpInside];

//当用户按下的时候触发

//[button1 addTarget:self action:@selector(touchDown) forControlEvents:UIControlEventTouchDown];

//当用户在触摸控件后在控件之外拖拖动时

//[button1 addTarget:self action:@selector(dragOutside) forControlEvents:UIControlEventTouchDragOutside];

//     当用户在触摸控件后在控件之内拖拖动时

//[button1 addTarget:self action:@selector(dragInside) forControlEvents:UIControlEventTouchDragInside];

//用户控件之外触摸抬按下时

//[button1 addTarget:self action:@selector(outside) forControlEvents:UIControlEventTouchUpOutside];

//触摸控件往外拖时

[button1 addTarget:self action:@selector(dragExit) forControlEvents:UIControlEventTouchDragExit];

//触摸控件往内拖时

[button1 addTarget:self action:@selector(dragEnter) forControlEvents:UIControlEventTouchDragEnter];

//多次触摸控件时触发

[button1 addTarget:self action:@selector(repeat) forControlEvents:UIControlEventTouchDownRepeat];

button1.backgroundColor = [UIColor whiteColor];

button1.titleLabel.font = [UIFont systemFontOfSize:18.0];

[button1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

//button1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

//button1.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);

self.window.backgroundColor = [UIColor purpleColor];

[self.window addSubview:button];

Xcode UIView 中的Button 控件的属性和基本用法的更多相关文章

  1. [原创]在Framelayout中放置button控件出现的覆盖问题

    android Framelayout(帧布局)是很常用的布局,主要用来处理需要多个view叠加显示的情况. 然而在使用中,我发现Framelayout中的Button控件,会挡住所有其他控件,而不论 ...

  2. listView中的button控件获取item的索引

    在listview中的listitem设置事件响应,如果listitem中有button控件,这时候listitem就不会捕获到点击事件,而默认的是listitem中的button会捕获点击事件.那么 ...

  3. Android-TextView 控件常用属性以及基本用法

    github地址:https://github.com/1165863642/TextViewDemo 前言 这是我第一次写博客,第一次的笔记,不足之处多谅解.开门见山,这一篇博客主要讲一下在Andr ...

  4. ios开发中button控件的属性及常见问题

    最为最基本的控件,我们必须对button的每个常用属性都熟练应用: 1,使用之前,必须对按钮进行定义,为乐规范,在@interface ViewController (){}中进行定义,先定义后使用. ...

  5. listView中的button控件获取索引

    1.在listitem中初始化button的时候,给该button添加一个setTag方法,将此时的索引值传进去,然后在button的onclick事件中调用view的getTag方法,即可将list ...

  6. sp.net2.0中的新增控件BulletedList的一些高级用法

    asp.net2.0新增了一个BulletedList控件,通过它可以以列表形式显示数据,而不必再用Repeater,Datalist等实现相同的效果.今天做程序的时候正好用到了这个控件,就把它的一些 ...

  7. 009. C#中的WebBrowser控件的属性、方法及操作演示代码(转)

    本文转自 http://www.open-open.com/code/view/1430559996802 0.常用方法 Navigate(string urlString):浏览urlString表 ...

  8. 【深入篇】Andorid中常用的控件及属性

    TextView  android:autoLink 设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none/web/email/phone/map/al ...

  9. Android关于ListView中item与控件抢夺焦点的那些事

    在开发中,listview可以说是我们使用最频繁的控件之一了,但是关于listview的各种问题也是很多.当我们使用自定义布局的Listview的时候,如果在item的布局文件里面存在Button或者 ...

随机推荐

  1. python中的monkey-patching

    这个技巧我很少用过. 但知道无防. 在运行时改变函数或类的行为, 一般用猴子补丁,原类,装饰器都可以实现. #!/usr/bin/env python # -*- coding: utf-8 -*- ...

  2. poj 2236:Wireless Network(并查集,提高题)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 677 ...

  3. RTP timestamp与帧率及时钟频率的关系

    转自:http://blog.csdn.net/jasonhwang/article/details/7316128 RTP timestamp是用时钟频率(clock rate)计算而来表示时间的. ...

  4. 禁用编译器自动生成的函数(Effective C++之06)

    如果想让你的类定义出来的对象是独一无二的,即对象无法被复制,或者使用赋值操作符赋给另外一个对象,那么最好的方法就是禁用拷贝构造函数和赋值操作符.下面介绍几种禁用的方法.(方法来自Effective C ...

  5. APP交互

    交互设计基本功!5个值得学习的APP交互方式http://www.uisdc.com/5-interactive-design-worth-learning 移动App交互设计10大趋势–你用到了吗? ...

  6. Activity有四种加载模式(转)

    Activity有四种加载模式: standard singleTop singleTask singleInstance 在多Activity开发中,有可能是自己应用之间的Activity跳转,或者 ...

  7. Json转换利器Gson之实例一-简单对象转化和带泛型的List转化 (转)

    Gson 是 Google 提供的用来在 Java 对象和 JSON 数据之间进行映射的 Java 类库.可以将一个 JSON 字符串转成一个 Java 对象,或者反过来. jar和源码下载地址: h ...

  8. 初识WCF

    以前,总是说自己的基础知识不牢靠,就是因为自己总是不总结.昨天,学费交了,顿时感觉不一样了,心里有劲也有力了,知道了以前的自己到底为什么会那样了,因为没有压力. --题记 我参加过浩哥的招标项目,参加 ...

  9. while do while以及穷举和迭代

    今天的新内容1:while循环 格式: while() { } 初始状态要在循环外提前规定 状态改变要写在花括号里面 括号内是循环条件 for循环与while循环的对比: 2:do while 不管循 ...

  10. UVA 11987 Almost Union-Find (并查集+删边)

    开始给你n个集合,m种操作,初始集合:{1}, {2}, {3}, … , {n} 操作有三种: 1 xx1 yy1 : 合并xx1与yy1两个集合 2 xx1 yy1 :将xx1元素分离出来合到yy ...