开发者

How can i create a my own custom button without using interface builder? [closed]

开发者 https://www.devze.com 2023-04-09 06:27 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消