UIButton *  button =[[UIButton alloc]init];
button.backgroundColor=[UIColor redColor];
[button setTitle:@"我是button" forState:UIControlStateNormal];
button.frame = CGRectMake(, , , ) ;
[self.view addSubview:button];

可能有时候,想让title不在中间或者靠某一边,现在就举个例子怎么把文字在button的底部。

代码:

 button.contentEdgeInsets = UIEdgeInsetsMake(, , , );

然后看一下 视图是这个样子:

这里边用到

button.contentEdgeInsets = UIEdgeInsetsMake(100, 0, 0, 0);  //UIEdgeInsetsMake(距离top的距离, 距离left的距离, 距离botton的距离, 距离right的距离)

//设置 button的内容的便宜量

@property(nonatomic)          UIEdgeInsets contentEdgeInsets UI_APPEARANCE_SELECTOR; // 这是内容的偏移量
@property(nonatomic) UIEdgeInsets titleEdgeInsets; // title的偏移量
@property(nonatomic) BOOL reversesTitleShadowWhenHighlighted; // default is NO. if YES, shadow reverses to shift between engrave and emboss appearance
@property(nonatomic) UIEdgeInsets imageEdgeInsets; // image的偏移量
@property(nonatomic) BOOL adjustsImageWhenHighlighted; // default is YES. if YES, image is drawn darker when highlighted(pressed)当高亮的时候if yes 图片自适应
 @property(nonatomic) BOOL adjustsImageWhenDisabled; // default is YES. if YES, image is drawn lighter when disabled
@property(nonatomic) BOOL showsTouchWhenHighlighted; // 当高亮的时候if yes 图片自适应
@property(nonatomic,retain) UIColor *tintColor NS_AVAILABLE_IOS(5_0); //高亮颜色 @property(nonatomic,readonly) UIButtonType buttonType; //button的类型

[button setTitleShadowColor:[UIColor redColor] forState:UIControlStateNormal];

//设置文字的边框颜色

不太明显,效果还是有的。

typedef NS_ENUM(NSInteger, UIButtonType) {
UIButtonTypeCustom = , // no button type
UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0), // standard system button UIButtonTypeDetailDisclosure,
UIButtonTypeInfoLight,
UIButtonTypeInfoDark, //
UIButtonTypeContactAdd, //按钮上面是哥加号 UIButtonTypeRoundedRect = UIButtonTypeSystem, //系统默认的
}; 创建button的另一中写法:

button =[UIButton buttonWithType:UIButtonTypeInfoDark];

- (void)setTitle:(NSString *)title forState:(UIControlState)state;                     // 设置button的title
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // 设置buttontitle的颜色
- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // default is nil. use 50% black设置title的字体的阴影颜色
- (void)setImage:(UIImage *)image forState:(UIControlState)state; // default is nil. should be same size if different for different states 设置button的image 图片 大小是图片的真实大小
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // default is nil 设置图片的背景 image会铺满button
- (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state NS_AVAILABLE_IOS(6_0); // default is nil. title is assumed to be single line 设置 自定义的字符串为button的title
- (NSString *)titleForState:(UIControlState)state;          //  获取某个状态的title
- (UIColor *)titleColorForState:(UIControlState)state; //获取某个状态的title的字体颜色
- (UIColor *)titleShadowColorForState:(UIControlState)state; //获得某个状态的阴影颜色
- (UIImage *)imageForState:(UIControlState)state; //获得某个状态的image
- (UIImage *)backgroundImageForState:(UIControlState)state; //获得背景图片
- (NSAttributedString *)attributedTitleForState:(UIControlState)state NS_AVAILABLE_IOS(6_0); //获得自定义字符串
@property(nonatomic,readonly,retain) NSString *currentTitle;             // normal/highlighted/selected/disabled. can return nil 正常获取当前的title
@property(nonatomic,readonly,retain) UIColor *currentTitleColor; // normal/highlighted/selected/disabled. always returns non-nil. default is white(1,1) 获取当前title的颜色
@property(nonatomic,readonly,retain) UIColor *currentTitleShadowColor; // normal/highlighted/selected/disabled. default is white(0,0.5).获取当前的阴影颜色
@property(nonatomic,readonly,retain) UIImage *currentImage; // normal/highlighted/selected/disabled. can return nil 获取当前的imager
@property(nonatomic,readonly,retain) UIImage *currentBackgroundImage; // normal/highlighted/selected/disabled. can return nil 获取当前的背景image
@property(nonatomic,readonly,retain) NSAttributedString *currentAttributedTitle NS_AVAILABLE_IOS(6_0); // normal/highlighted/selected/disabled. can return nil // return title and image views. will always create them if necessary. always returns nil for system buttons
@property(nonatomic,readonly,retain) UILabel *titleLabel NS_AVAILABLE_IOS(3_0); 获取content的view 就是一个lable
@property(nonatomic,readonly,retain) UIImageView *imageView NS_AVAILABLE_IOS(3_0); imageView 就是button的image的试图
 (CGRect)backgroundRectForBounds:(CGRect)bounds;
- (CGRect)contentRectForBounds:(CGRect)bounds;
- (CGRect)titleRectForContentRect:(CGRect)contentRect;
- (CGRect)imageRectForContentRect:(CGRect)contentRect;
@end @interface UIButton(UIButtonDeprecated) @property(nonatomic,retain) UIFont *font NS_DEPRECATED_IOS(2_0, 3_0);//通过这个可以给title设置字体
@property(nonatomic) NSLineBreakMode lineBreakMode NS_DEPRECATED_IOS(2_0, 3_0);// 换行模式
@property(nonatomic) CGSize titleShadowOffset NS_DEPRECATED_IOS(2_0, 3_0); // title的偏移量 @end

最新文章

  1. PHP数组操作汇总 php数组的使用技巧
  2. PLSQL 逻辑多线程
  3. C# 我理解的接口、抽象类、以及事件
  4. poj 2632 Crashing Robots_模拟
  5. JVM ClassLoader加载过程
  6. OCA读书笔记(3) - 使用DBCA创建Oracle数据库
  7. H - transaction transaction transaction
  8. 01_Python简介
  9. javascript 常用方法 解析URL,补充前导字符
  10. 【算法】二分查找法&大O表示法
  11. ubuntu apt-get 安装指定版本软件
  12. Python正则表达式 学习笔记
  13. mysql存储引擎管理使用
  14. java并发中的锁
  15. mac os maverick下安装nginx+php-fpm via homebrew
  16. VS中C#连接SQLite数据库处理器架构“x86”不匹配的问题
  17. STM32F10x_SPI(硬件接口 + 软件模拟)读写Flash(25Q16)
  18. 单链表删除(Delete)或者去除(Remove)节点面试题总结
  19. JavaScript工作机制:V8 引擎内部机制及如何编写优化代码的5个诀窍
  20. Python闭包的高级应用-装饰器的实现

热门文章

  1. Ext.grid.GridPanel的属性
  2. iOS开发之性能优化
  3. flac文件提取专辑封面手记
  4. (Qt 翻译) QGLSceneNode
  5. 关于各种数据库 Insert时同时取到Id的操作
  6. centos下python的pymssql模块安装及简单使用
  7. JNDI support differences between Tibco EMS and ActiveMQ
  8. 鼠标拖放div 实现
  9. qt运行库
  10. Python学习笔记9-Python 链接MySql数据库