iOS控件之UIButton篇
来源:互联网 发布:淘宝背景怎么下调 编辑:程序博客网 时间:2024/05/19 02:21
UIButton *signBtn = [UIButton buttonWithType:UIButtonTypeCustom];
signBtn.frame = CGRectMake(0, 0, 80, 40);
[signBtn.layer setMasksToBounds:YES];
[signBtn.layer setCornerRadius:10.0]; //设置矩形四个圆角半径
[signBtn.layer setBorderWidth:1.0]; //边框宽度
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 1, 0, 0, 1 });
[signBtn.layer setBorderColor:colorref];//边框颜色
[signBtn setTitle:@"还 原" forState:UIControlStateNormal];//button title
[signBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];//title color
[signBtn addTarget:self action:@selector(buttonDonwRecover:) forControlEvents:UIControlEventTouchUpInside];//button 点击回调方法
signBtn.backgroundColor = [UIColor whiteColor];
- (void)buttonDonwRecover:(id)sender
{
UIButton *btn = (UIButton *)sender;
}
btn.frame = CGRectMake(x, y, width, height);
[btn setTitle: @"search" forState: UIControlStateNormal];
//设置按钮上的自体的大小
//[btn setFont: [UIFont systemFontSize: 14.0]]; //这种可以用来设置字体的大小,但是可能会在将来的SDK版本中去除改方法
//应该使用
btn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
[btn seBackgroundColor: [UIColor blueColor]];
//最后将按钮加入到指定视图superView
[superView addSubview: btn];
==========================================================
tvnamelabel=[[UIButton alloc]initWithFrame:CGRectMake(5,5,200,40)];
这样初始化的button,文字默认颜色是白色的,所有如果背景也是白色的话,是看不到文字的,
btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft ;//设置文字位置,现设为居左,默认的是居中
[btn setTitle:@“title”forState:UIControlStateNormal];// 添加文字
有些时候我们想让UIButton的title居左对齐,我们设置
btn.textLabel.textAlignment = UITextAlignmentLeft
是没有作用的,我们需要设置
btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft;
但是问题又出来,此时文字会紧贴到做边框,我们可以设置
btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
使文字距离做边框保持10个像素的距离。
=======================================================
设置UIButton上字体的颜色设置UIButton上字体的颜色,不是用:
[btn.titleLabel setTextColor:[UIColorblackColor]];
btn.titleLabel.textColor=[UIColor redColor];
而是用:
[btn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
- iOS控件之UIButton篇
- iOS控件之UIButton
- ios基本控件之UIButton
- iOS UI控件之----UIButton
- 学习ios控件之UIButton
- IOS开发(16)之UIButton控件
- iOS-UI-基本控件之UIButton
- iOS UI基础控件之UIButton
- iOS自学笔记之UIButton控件
- Xamarin.iOS-UIButton和UIAlertView【控件篇】
- IOS 控件 UIButton button
- IOS UI控件 - UIButton
- 基本控件之UIButton
- UI控件之UIButton
- iOS开发之四:常用控件--UIButton的使用
- ios-UI控件精讲之【6】UIButton
- UIButton按钮控件-iOS开发
- iOS开发基础控件--UIButton
- android Eclipse自动编译NDK/JNI的三种方法
- windbg图解
- 哪些情况下女人最容易出轨
- 使用NEWID()搭配UniqueIdentifier数据产生全球唯一标识码
- 关键字 final & private
- iOS控件之UIButton篇
- leetcode之single number
- MFC中CSliderCtrl的使用(收集)
- ExtJS中的accordion布局如何展开特定的item
- 字符串-04 字符串逆序(15)
- 关于oracle登录出现ORACLE initialization or shutdown in progress
- Android基础和进阶知识总结
- JS event使用方法详解
- ORA-12154: TNS:could not resolve the connect identifier specified