在view左上角原点处绘制Button
载:http://nachbaur.com/blog/building-a-custom-dashboard-uibutton
?
As part of the Parking Mobility iPhone app I’ve been building, I wanted to integrate a simple “Quick Start” help guide to show people how to use the app without being intrusive.? I wanted to use the project’s branding as much as possible, and give the user a feeling like they haven’t left the main portion of the app.? So I wanted the user to be comfortable with it, and always have a quick way to close the help window to get back to the app.
The end result is actually really simple.? I subclassed the UIButton class, and overrode the drawRect: method to use some native drawing primitives.
CGFloat closeSize = 26.0;CGRect butframe = CGRectMake(0.0, 0.0, closeSize, closeSize);butframe.origin.x = contentView.frame.origin.x - closeSize / 2;butframe.origin.y = contentView.frame.origin.y - closeSize / 2;DNCloseButton *button = [[[DNCloseButton alloc] initWithFrame:butframe] autorelease];[button addTarget:self action:@selector(closePopup:) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:button];?
If you find any bugs in this code, please let me know and I’ll update this post.? I hope this works out as well for you as it has for me.
?