0
我需要一個項目,我正在處理類似於郵件應用程序用來顯示聯繫人的按鈕。郵件應用程序的電子郵件按鈕iPhone
如果你不明白我在說什麼,請參閱本圖片:http://www.aboutptc.net/theButtonIneed.png
在此先感謝。
我需要一個項目,我正在處理類似於郵件應用程序用來顯示聯繫人的按鈕。郵件應用程序的電子郵件按鈕iPhone
如果你不明白我在說什麼,請參閱本圖片:http://www.aboutptc.net/theButtonIneed.png
在此先感謝。
郵件應用程序的按鈕是一個無證的類。儘管如此,您可以使用自定義的可伸縮背景圖像和UIButton輕鬆地模擬此操作。
這裏是代碼...你需要從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: @"[email protected]"] 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: @"[email protected]"] 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;
}
感謝您的回答,但我在哪裏可以找到使用的圖像? – clide313 2010-03-03 12:58:42
@user:查看模擬器SDK中的MessageUI.framework文件夾。 – kennytm 2010-03-03 13:22:01
我finaly重新創建圖像,並使用UIButton來模擬它。 – clide313 2010-03-20 19:25:21