How can i create a my own custom button without using interface builder? [closed]
I want to create my own custom button without using any interface builder.
Actually i wants to set all my properties/attribute(Like frame,color,size,label etc.) separate in a NSObject class.Then from my UIView class i want to draw them .
How can开发者_如何转开发 i do it as i am never use NSObject class?
Any sample application or example to do this?
Actually, you can subclass UIButton
- for an example, have a look at Fun With UIButtons and Core Animation Layers. Is this is too much, you can simply create a new UIButton
and set it's properties:
UIButton *btn = [[UIButton alloc] initWithFrame:yourFrame]
btn.backgroundColor = [UIColor redColor];
...
[btn release;]
Check this Code:
UIButton *btn=[[UIButton alloc] initWithFrame:CGRectMake(152,0,150,128)];
[btn setBackgroundColor:[UIColor clearColor]];
[btn setImage:actualImage forState:UIControlStateNormal];
[btn setTag:1];
[btn addTarget:self action:@selector(btnTouched:)forControlEvents:UIControlEventTouchDown];
[self addSubview:btn];
[btn release];
精彩评论