UIButton的使用

UIButton的代码实现:

定义:

    UIButton * switchButton;

创建:

    switchButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];


添加到屏幕上:

    [primaryView addSubview:switchButton];

修改属性的方法:

    //Button的位置和大小

    CGRect buttonRect = CGRectMake(BUTTON_XBUTTON_YBUTTON_LENGTHBUTTON_HEIGHT);

    switchButton.frame = buttonRect;

    //Button的字和颜色

    [switchButtonsetTitle:@"滤镜效果" forState:UIControlStateNormal];

    [switchButtonsetTitleColor:[UIColorcolorWithRed:255green:0blue:255alpha:1forState:UIControlStateNormal];

    //Button的背景图片

    UIImage * tempButtonImg = [UIImage imageNamed:@"artwork.png"];

    [switchButtonsetBackgroundImage:tempButtonImg forState:UIControlStateNormal];

设置响应和委托:

    //设置UIButton的响应事件

    [saveButtonaddTarget:selfaction:@selector(pressSaveButton:) forControlEvents:UIControlEventTouchUpInside];


posted @ 2013-10-30 09:17  wisejoker  阅读(80)  评论(0编辑  收藏  举报