2010-03-03 87 views

回答

4

郵件應用程序的按鈕是一個無證的類。儘管如此,您可以使用自定義的可伸縮背景圖像和UIButton輕鬆地模擬此操作。

+0

感謝您的回答,但我在哪裏可以找到使用的圖像? – clide313 2010-03-03 12:58:42

+0

@user:查看模擬器SDK中的MessageUI.framework文件夾。 – kennytm 2010-03-03 13:22:01

+0

我finaly重新創建圖像,並使用UIButton來模擬它。 – clide313 2010-03-20 19:25:21

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: @"[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; 
} 
相關問題