【学习笔记】UIButton
来源:互联网 发布:雷霆vs勇士第六场数据 编辑:程序博客网 时间:2024/06/07 22:55
// UIButton.h
#import <Foundation/Foundation.h>
#import <UIKit/UIControl.h>
#import <UIKit/UIGeometry.h>
#import <UIKit/UIStringDrawing.h>
#import <UIKit/UIKitDefines.h>
@class UIImage, UIFont,UIColor,UIImageView,UILabel;
//button样式选择,默认是无
typedef NS_ENUM(NSInteger, UIButtonType) {
UIButtonTypeCustom = 0, 自定义风格(无边框的那种)
UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0), 圆角矩形(系统的那种)
UIButtonTypeDetailDisclosure, (ios7上变成一个亮的蓝色感叹号)
UIButtonTypeInfoLight, 亮色感叹号
UIButtonTypeInfoDark, 暗色感叹号
UIButtonTypeContactAdd, 十字加号按钮
};
NS_CLASS_AVAILABLE_IOS(2_0)@interfaceUIButton : UIControl <NSCoding>
+ (id)buttonWithType:(UIButtonType)buttonType;
//创建button,选择样式
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//位置
button1.frame = CGRectMake(100,100,50,50);
[self.view add :buttob ];
内容到边缘距离(上左下右)
@property(nonatomic) UIEdgeInsets contentEdgeInsetsUI_APPEARANCE_SELECTOR;
btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0,0);
标题到边缘距离,同上
@property(nonatomic) UIEdgeInsets titleEdgeInsets;
图片到边缘距离,同上
@property(nonatomic) UIEdgeInsets imageEdgeInsets;
确定按钮高亮时是否改变阴影的Bool值.默认时NO
@property(nonatomic) BOOL reversesTitleShadowWhenHighlighted;
图片随按钮高亮而高亮,默认YES
@property(nonatomic) BOOL adjustsImageWhenHighlighted;
btton.adjustsImageWhenHighlighted = NO;
图片随按钮失效而变暗,默认YES
@property(nonatomic) BOOL adjustsImageWhenDisabled;
按下会有白色光点,默认NO
@property(nonatomic) BOOL showsTouchWhenHighlighted;
@property(nonatomic,retain) UIColor *tintColor NS_AVAILABLE_IOS(5_0);
// The tintColor is inherited through the superview hierarchy.See UIView for more information.
//标题文字
- (void)setTitle:(NSString*)title forState:(UIControlState)state;
[button1 setTitle:@"BTN1" forState:UIControlStateNormal];
// 标题颜色,默认正常黑
- (void)setTitleColor:(UIColor*)color forState:(UIControlState)stateUI_APPEARANCE_SELECTOR;
[button1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
// 阴影颜色,默认50%
- (void)setTitleShadowColor:(UIColor*)color forState:(UIControlState)stateUI_APPEARANCE_SELECTOR;
[button1 setTitleShadowColor:[UIColor grayColor] forState:UIControlStateNormal];
// 设置图片,原来大小,默认无
- (void)setImage:(UIImage*)image forState:(UIControlState)state;
//[button1 setImage:[UIImage imageNamed:@"image"] forState:UIControlStateNormal];
// 设置背景图片,拉伸或压缩,默认无
- (void)setBackgroundImage:(UIImage*)image forState:(UIControlState)stateUI_APPEARANCE_SELECTOR;
[button1 setBackgroundImage:[UIImage imageNamed:@"P"] forState:UIControlStateHighlighted];
//上述5个对应选择状态
- (void)setAttributedTitle:(NSAttributedString*)title forState:(UIControlState)stateNS_AVAILABLE_IOS(6_0);
- (NSString *)titleForState:(UIControlState)state;
- (UIColor *)titleColorForState:(UIControlState)state;
- (UIColor *)titleShadowColorForState:(UIControlState)state;
- (UIImage *)imageForState:(UIControlState)state;
- (UIImage *)backgroundImageForState:(UIControlState)state;
返回在某个状态下,按钮标题的富文本
- (NSAttributedString *)attributedTitleForState:(UIControlState)stateNS_AVAILABLE_IOS(6_0);
NSAttributedString *attributedString = [button
attributedTitleForState:UIControlStateNormal];
得到当前状态(只读)
@property(nonatomic,readonly)UIButtonType buttonType;
//当前按钮上显示的标题(只读),当按钮状态改变时值自动改变.值可以为nil.
@property(nonatomic,readonly,retain)NSString*currentTitle;
当前标题颜色(只读).此值要保证不为nil,默认是白色
@property(nonatomic,readonly,retain)UIColor *currentTitleColor;
// 标题的阴影颜色(只读).默认是白色
@property(nonatomic,readonly,retain)UIColor *currentTitleShadowColor;
当前按钮上的图片(只读).可以是nil.
@property(nonatomic,readonly,retain)UIImage *currentImage;
// 当前按钮背景图片(只读).可以是nil.
@property(nonatomic,readonly,retain)UIImage *currentBackgroundImage;
@property(nonatomic,readonly,retain)UILabel *titleLabel NS_AVAILABLE_IOS(3_0);
@property(nonatomic,readonly,retain)UIImageView*imageView NS_AVAILABLE_IOS(3_0);
@property(nonatomic,readonly,retain)NSAttributedString*currentAttributedTitle NS_AVAILABLE_IOS(6_0);
得到尺寸
返回背景绘制区域
- (CGRect)backgroundRectForBounds:(CGRect)bounds;
返回内容绘制区域.内容区域是显示图片和标题及他们特定对齐缩放等的范围
- (CGRect)contentRectForBounds:(CGRect)bounds;
返回标题的绘制区域.
- (CGRect)titleRectForContentRect:(CGRect)contentRect;
返回图片的绘制区域.
- (CGRect)imageRectForContentRect:(CGRect)contentRect;
@end
@interfaceUIButton(UIButtonDeprecated)
@property(nonatomic,retain)UIFont *font NS_DEPRECATED_IOS(2_0,3_0);
@property(nonatomic) NSLineBreakMode lineBreakMode NS_DEPRECATED_IOS(2_0,3_0);
@property(nonatomic) CGSize titleShadowOffsetNS_DEPRECATED_IOS(2_0,3_0);
@end
UIControlState 状态
1 UIControlStateNormal = 0,
2 UIControlStateHighlighted = 1 << 0, // 高亮
3 UIControlStateDisabled = 1 << 1,
4 UIControlStateSelected = 1 << 2, // 选中
5 UIControlStateApplication = 0x00FF0000, // 当应用程序标志使用时
6 UIControlStateReserved = 0xFF000000 // 为内部框架预留
UIControlEvents 事件方法
- UIControlEventTouchDown = 1 << 0,
- UIControlEventTouchDownRepeat = 1 << 1,
- UIControlEventTouchDragInside = 1 << 2,
- UIControlEventTouchDragOutside = 1 << 3,
- UIControlEventTouchDragEnter = 1 << 4,
- UIControlEventTouchDragExit = 1 << 5,
- UIControlEventTouchUpInside = 1 << 6, 基本就用这个
- UIControlEventTouchUpOutside = 1 << 7,
- UIControlEventTouchCancel = 1 << 8,
- UIControlEventValueChanged = 1 << 12,
- UIControlEventEditingDidBegin = 1 << 16,
- UIControlEventEditingChanged = 1 << 17,
- UIControlEventEditingDidEnd = 1 << 18,
- UIControlEventEditingDidEndOnExit = 1 << 19,
- UIControlEventAllTouchEvents = 0x00000FFF,
- UIControlEventAllEditingEvents = 0x000F0000,
- UIControlEventApplicationReserved = 0x0F000000,
- UIControlEventSystemReserved = 0xF0000000,
- UIControlEventAllEvents = 0xFFFFFFFF
- UIButton学习笔记
- 【学习笔记】UIButton
- IOS学习笔记UIButton
- UIButton 学习笔记
- UIButton学习笔记
- IOS开发学习笔记(2)-----UIButton 详解
- IOS开发学习笔记(2)-----UIButton 详解
- IOS学习笔记---UIKit之UIButton
- iOS学习笔记(3)UIButton
- iOS UI篇 学习笔记 UIButton,UIImageView
- iOS UI学习笔记(四)UIButton
- IOS学习笔记(三)之UIButton
- [赵三哥Swift学习笔记]UIButton
- IOS学习笔记(7)UIButton UIImageView UIScrollView UIWebView
- iOS学习笔记(七)——UI基础UIButton
- IOS学习笔记(7)UIButton UIImageView UIScrollView UIWebView
- 【初学】UI控件学习笔记-UIButton按钮控件详细介绍
- iOS学习笔记(29) 爱不释手的ReactiveCocoa之UIButton
- 在Centos中导入sql文件的方法
- openssl cmd
- cocos2dx用checkbox实现单选框和button实现table按钮
- 安装Jdk8后请注意环境变量!
- 第二章作业P51.16(输入三个整数a,b,c,请按从小到大的顺序输出。)
- 【学习笔记】UIButton
- org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class
- VS2010无法调试问题解决
- 站内信息设计
- java 散乱知识点
- JedisPool介绍
- 第八章 - 轮廓 - 深入分析轮廓
- Android Launcher分析和修改5——HotSeat分析
- ios-day19-01(Block详解)