UI for iOS(四) -- UIButton添标题文字
来源:互联网 发布:哈尔滨大麦网络 编辑:程序博客网 时间:2024/06/05 21:54
by SevenJohs.
复选框设计
// QWCheckBox.m// QWPlanInfo//// Created by SevenJohs on 16/4/22.// Copyright © 2016年 ecity. All rights reserved.//#import "QWCheckBox.h"#import <UIKit/UIKit.h>@implementation QWCheckBox/*// Only override drawRect: if you perform custom drawing.// An empty implementation adversely affects performance during animation.- (void)drawRect:(CGRect)rect { // Drawing code}*///重写父类方法-(instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if(self){ self.titleLabel.textAlignment = NSTextAlignmentRight; self.titleLabel.font = [UIFont systemFontOfSize:12]; self.titleLabel.textColor = [UIColor redColor]; self.imageView.contentMode = UIViewContentModeLeft; [self setBackgroundImage:[UIImage imageNamed:@"checkbox"] forState:UIControlStateNormal]; [self setBackgroundImage:[UIImage imageNamed:@"checkbox_selected"] forState:UIControlStateSelected]; } return self;}-(CGRect)titleRectForContentRect:(CGRect)contentRect{ CGFloat posW = self.frame.size.width - self.frame.size.height - 4 ; CGFloat posH = self.frame.size.height ; CGFloat posX = 0 ; CGFloat posY = 0 ; contentRect = CGRectMake(posX, posY, posW, posH); return contentRect;}-(CGRect)imageRectForContentRect:(CGRect)contentRect{ CGFloat posW = self.frame.size.height - 14 ; CGFloat posH = self.frame.size.height - 14 ; CGFloat posX = self.frame.size.width - posW - 25 ; CGFloat posY = 0 ; contentRect = CGRectMake(posX, posY, posW, posH); return contentRect;}
cell中实现代理方法
@protocol PlanInfoDelegate ;@interface QWPlanInfoCell : UITableViewCell//设置cell中的点击操作、值变化委托@property (nonatomic,assign)id<PlanInfoDelegate> delegate;@property (nonatomic, retain) QWCheckBox* checkBoxBtn;@end@protocol PlanInfoDelegate <NSObject>-(void)planInfoCell:(QWPlanInfoCell*)cell stateChageForInfo:(QWPlanInfo *)data;@end/** * 根据父视图的大小设置CheckBox的frame,并传入数据 * @param rect 父视图frame * @param data 数据 */-(void)updateCheckBoxSubviewsFrame:(CGRect)rect data:(QWPlanInfo *)data{ CGFloat width = 30; CGFloat height = 12; CGFloat startX = (rect.size.width - EGDE_MARGIN*2)/2.5 * 2 ; CGFloat startY = (rect.size.height - height)/2; self.checkBoxBtn.frame = CGRectMake(startX, startY,width, height); self.checkBoxBtn.titleLabel.text = @"显示"; [self.checkBoxBtn addTarget:self action:@selector(checkBoxClickAction) forControlEvents:UIControlEventTouchUpInside];}/** * 点击checkBox触发事件 */-(void)checkBoxClickAction{ if(self.delegate){ [self.delegate planInfoCell:self stateChageForInfo:_data]; }}
0 0
- UI for iOS(四) -- UIButton添标题文字
- iOS UI学习笔记(四)UIButton
- UIButton获取标题文字
- UIButton获取标题文字
- IOS ui基础 uibutton
- IOS UI控件 - UIButton
- IOS UI 手写 UIButton
- iOS UI界面之UIButton
- iOS UI界面之UIButton
- iOS开发UI篇 -- UIButton
- iOS-UI-02 UILabel UIButton
- IOS--UI--UIButton的使用
- iOS学习UI之UIButton
- iOS之UI学习-UIButton
- iOS UI控件之----UIButton
- iOS开发笔记-UI-UIButton
- IOS 自定义标题文字
- IOS学习(四)UIButton
- 小白学习笔记------关于数据库报错“二进制字符截断”
- Android之手机屏幕朝向
- OpenCV之calib3d 模块. 相机定标和三维重建
- 最全的css Hack
- 基于gevent和pymysql实现mysql读写的异步非堵塞方案
- UI for iOS(四) -- UIButton添标题文字
- android 代码+xml 设置光标颜色
- servlet与Web.xml配置关联
- 框架&Maven
- Oracle 11g笔记——后台进程
- 聊聊同步异步、阻塞非阻塞
- SVN使用教程总结
- 那些年放久了的鸡汤
- WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!