UIButton的标题知识点详解

作者: shaneZhang 分类: ios技术 发布时间: 2014-09-03 10:10

UILineBreakMode的各种情况 

UILineBreakMode
Options for wrapping and truncating text. (Deprecated. Use NSLineBreakMode instead.)
typedef enum { 
   UILineBreakModeWordWrap = 0, 
   UILineBreakModeCharacterWrap, 
   UILineBreakModeClip, 
   UILineBreakModeHeadTruncation, 
   UILineBreakModeTailTruncation, 
   UILineBreakModeMiddleTruncation, 
} UILineBreakMode;

NSLineBreakMode
These constants specify what happens when a line is too long for its container.
enum {
   NSLineBreakByWordWrapping = 0,
   NSLineBreakByCharWrapping,
   NSLineBreakByClipping,
   NSLineBreakByTruncatingHead,
   NSLineBreakByTruncatingTail,
   NSLineBreakByTruncatingMiddle
};
typedef NSUInteger NSLineBreakMode

 
lineBreak模式在6.0之前一直用UILineBreakMode枚举类型,6.0使用NSLineBreakMode枚举类型。枚举值中各个值的意义,解释如下:
   UILineBreakModeWordWrap = 0, 
   以单词为单位换行,以单位为单位截断。 
   UILineBreakModeCharacterWrap, 
   以字符为单位换行,以字符为单位截断。 
   UILineBreakModeClip, 
   以单词为单位换行。以字符为单位截断。 
   UILineBreakModeHeadTruncation, 
   以单词为单位换行。如果是单行,则开始部分有省略号。如果是多行,则中间有省略号,省略号后面有4个字符。 
   UILineBreakModeTailTruncation, 
   以单词为单位换行。无论是单行还是多行,都是末尾有省略号。 
   UILineBreakModeMiddleTruncation, 

   以单词为单位换行。无论是单行还是多行,都是中间有省略号,省略号后面只有2个字符。

设置UIButton的文字显示位置、字体的大小、字体的颜色
分类: iphone界面详解 2012-12-21 14:32 17546人阅读 评论(2) 收藏 举报
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];

本页面支持繁体中文友好显示:UIButton的标题知识点详解

如果觉得我的文章对您有用,请随意打赏。如果有其他问题请联系博主QQ(909491009)或者下方留言!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注