Extending UIButton for multiline & position of textLabel?
Extending UIButton for multiline & position of textLabel?
- Subject: Extending UIButton for multiline & position of textLabel?
- From: "Eric E. Dolecki" <email@hidden>
- Date: Thu, 17 Dec 2009 10:46:02 -0500
I have a custom button where I am supplying the artwork. The artwork for the
button has an icon represented on it's background, so I want the textLabel
for the custom button (extends UIButton) to offset to the right.
What I have so far works for about a second, and then the frame for the
textLabel snaps back to it's default position, the text now covering the
whole button (not what I want).
My custom button (h & m):
#import <Foundation/Foundation.h>
@interface EventButton : UIButton {
}
- (id)init;
@end
-------
#import "EventButton.h"
@implementation EventButton
- (id) init {
if( self = [super init]){
self.frame = CGRectMake( 0, 0, 468, 50 );
UIImage *image = [UIImage imageNamed:@"eventButton.png"];
UIImage *stretchImage = [image stretchableImageWithLeftCapWidth:15.0
topCapHeight:0.0];
[self setBackgroundImage:stretchImage forState:UIControlStateNormal];
self.backgroundColor = [UIColor clearColor];
self.titleLabel.numberOfLines = 0;
self.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
self.titleLabel.textAlignment = UITextAlignmentLeft;
self.titleLabel.font = [UIFont systemFontOfSize:12];
}
return self;
}
- (void) drawRect:(CGRect)frame {
[super drawRect:frame];
self.titleLabel.frame = CGRectMake(60, 0, 400, 50);
}
@end
I am calling this button up like so in a view:
EventButton *testButton = [[EventButton alloc] init];
[testButton setTitle:@"This is a really long title for the custom button and
it goes on to fill more than one line in the custom control"
forState:UIControlStateNormal];
testButton.tag=100;
[testButton addTarget:self action:@selector(SelectAlert:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:testButton];
How do I keep the textLabel properly sized so as not to interfere with the
icon artwork in the button background (which is on the left side)?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden