Tuesday, 16 October 2012

Setting any kind of image to UIButton without streaching in iPhone

UIButton *sampleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [sampleButton setFrame:CGRectMake(10, 10, 500, 30)];
    [sampleButton setTitle:@"Button" forState:UIControlStateNormal];
    [sampleButton setFont:[UIFont boldSystemFontOfSize:15]];
    [sampleButton setTag:1];
    UIImage *buttonImage = [[UIImage imageNamed:@"lbl_rightcut_small"]
                            resizableImageWithCapInsets:UIEdgeInsetsMake(0, 16, 0, 16)];
    [sampleButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
    [self.view addSubview:sampleButton]; 

No comments:

Post a Comment