我需要一个项目,我正在使用一个类似于Mail应用程序用来显示联系人的按钮。
如果您没有看到我在说什么,请看这张图片:http://www.aboutptc.net/theButtonIneed.png
提前致谢。
答案 0 :(得分:4)
Mail App的按钮是一个未记录的类。
尽管如此,您可以使用自定义可伸缩背景图像和UIButton轻松模拟这一点。
答案 1 :(得分:0)
以下是代码...您需要从MessageUI.framework
:
-(UIButton *) buttonForComposeName:(NSString *) name{
UIButton *button;
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
CGSize stringSize=[name sizeWithFont:[UIFont fontWithName:@"Helvetica" size:20]];
[button setFrame:CGRectMake(0,0, stringSize.width+10, 20)];
[button setTitle:name forState:UIControlStateNormal];
[button addTarget:self action:@selector(composeNameButtonTapped:) forControlEvents:UIControlEventAllEvents];
UIImage *image = [[UIImage imageNamed: @"Compose_atom@2x.png"] stretchableImageWithLeftCapWidth:25 topCapHeight:0];
image=[MailRect imageWithImage:image scaledToSize:CGSizeMake(button.frame.size.width*2, 40)];
[button setBackgroundImage:image forState:UIControlStateNormal];
}
-(void) composeNameButtonTapped:(id)sender{
((UIButton *)sender).selected=YES;
UIImage *imageSelected = [[UIImage imageNamed: @"compose_atom_selected@2x.png"] stretchableImageWithLeftCapWidth:25 topCapHeight:0];
imageSelected=[MailRect imageWithImage:imageSelected scaledToSize:CGSizeMake(((UIButton *)sender).frame.size.width*2, 40)];
[((UIButton *)sender) setBackgroundImage:imageSelected forState:(UIControlStateSelected)];
}
+ (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}