2016年1月28日

一、预先自定义控件样式,类似于重写构造函数,例如 UIButton,需要自带边框线的button,则可以自定义一个
YDgridButton
@implement
-(vioid)drawRect:(CGRect)rect
{
// 设置自定义的样式
}
@end

在调用时,指定button的style为 custom,然后将button指定为YDgridButton
则button的样式就是带边框的

二、control和xib关联
为了叙述方便,叫customControl和customXib
2.1、要将control指定为xib的file owner
2.2、view要关联到file Owner
2.3、在control的初始化函数里,要调用 initWithNib
-(instanceType)init
{
if( self =[ [ super alloc ] initWithNib:@”customXib” option:nil] )
{ }
return self;
}

三、动态添加控件时的注意点
如果要以懒加载的方式动态添加控件,将控件写成strong类型
@property (nonatomic,strong) UIButton *button;

 如果直接在viewDidLoad里写,应写成weak类型
@property (nonatomic,weak) UIButton *button;
-(void)viewDidLoad
{
UIButton *button = [[UIButton alloc]init];
[self.view addSubView:button];
_button = button;
[super viewDidLoad];
}

四、在appDelegate里手动加载根控制器
为了叙述方便,根视图叫customRootView
4.1 首先要获取根window
UIWindow *window =[ [UIApplication shareApplication] rootWindow]; // 大概是这么写
// 生成根视图
customRootView *customRootView = [[customRootView alloc]init];
// 用navigation来盛放这个view
UINavigation *nav = [[UINavigation alloc]initWithRootControl:customRootView];
// 接着将nav指定为根视图
window.rootViewControl = nav;
没有4.2了

五、关于handler的感想,是一个最纯粹的业务层,不涉及用户交互也不涉及页面布局。应该独立地抽出一层。
写的时候应该有一个baseHandler

typedef void(^completionBlock)(id obj) ;
typedef void(^successBlock)(id obj) ;
typedef void(^FailedBlock)(id obj) ;

@interface BaseHandler:NSObject

@end

具体的业务handler类继承这个base类

MonitorHandler类

@interface MonitorHandler:BaseHandler

-(void)executeMonitorWithParam:(customEntity *)entity success:( SuccessBlock )success fail:(FailBlock)fail;

@end

六、从xib里加载cell的法子
static NSString *CellIdentifier = @”Cell”; // 写上xib文件的名称
Cell cell = (Cell )[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // 查看是否有可复用的cell
if (!cell)
{
cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([Cell class])
owner:self
options:nil] objectAtIndex:0];
}
return cell;
*小结:NSBundle mainBundle 用于加载资源文件,xib也是资源,所以也能用这种方式加载

一、button样式设置
1.1 选择你喜欢的背景图片
1.2 用resizableImageWithCapInsets方法
UIImage *buttonImage = [[UIImage imageNamed:@”orangeButton.png”]
resizableImageWithCapInsets:UIEdgeInsetsMake(18, 18, 18, 18)];
UIImage *buttonImageHighlight = [[UIImage imageNamed:@”orangeButtonHighlight.png”]
resizableImageWithCapInsets:UIEdgeInsetsMake(18, 18, 18, 18)];

// Set the background for any states you plan to use
[saveButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
[saveButton setBackgroundImage:buttonImageHighlight forState:UIControlStateHighlighted];

很简单的。在这里你可以改变按钮的尺寸,而无需创建一个新的图像。`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值