UIButton的用法
来源:互联网 发布:中信债券优化净值走势 编辑:程序博客网 时间:2024/05/09 01:44
UIButton的用法
(2013-06-03 20:22:12)UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//非公开的按钮风格,改变按钮颜色方法
// [button setTintColor:[UIColor blueColor]];
[button setFrame:CGRectMake((320-200)/2, 150, 200, 50)];
//设置title---------(一些基本属性都可以设置 普通状态 和 高亮选中状态不同显示)
[button setTitle:@"present1233333" forState:UIControlStateNormal];
[button setTitle:@"高亮状态" forState:UIControlStateHighlighted];
NSString *path = [[NSBundle mainBundle] pathForResource:@"ab" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
//设置背景图片或者追加图片---------在按钮中:(1)同时有title,image,追加状态
//(2)但是image范围太大,会把title挤出去
[button setImage:image forState:UIControlStateNormal] ;
[button setTag:102];//设置tag值
//设置背景颜色,图片---------前提是button的type不能为白色圆角矩形,因为太大,button都被白色覆盖了
button.backgroundColor = [UIColor greenColor];
[button setBackgroundImage:image forState:UIControlStateHighlighted];
//设置文字颜色
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//设置阴影---颜色,偏移量
[button setTitleShadowColor:[UIColor blueColor] forState:UIControlStateNormal];
button.titleLabel.shadowOffset = CGSizeMake(2, 0);
//设置文字字号
NSArray *familyNames = [UIFont familyNames];
for(NSString *familyName in familyNames)
{
NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];
for(NSString *fontName in fontNames)
{
NSLog(@"fontName = %@",fontName);
}
}
//设置文字所处位置,左对齐,右对齐,水平居中对齐。上对齐,下对齐,垂直居中对齐。
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
//设置文字超过button显示时的显示方式(换行符方式)。6种方式
// typedef enum {
// UILineBreakModeWordWrap = 0, // Wrap at word boundaries
// UILineBreakModeCharacterWrap, // Wrap at character boundaries
// UILineBreakModeClip,
//