2012-01-30 14 views
9

मेरा ऐप एक कस्टम पृष्ठभूमि छवि के साथ एक बटन रख रहा है और मुझे इसके चारों ओर की सीमा की आवश्यकता नहीं है। मुझे यकीन नहीं है कि सीमा को कैसे हटाया जाए। मेरा कोड है:ios5: UIButton सीमा हटाएं

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    button.frame=CGRectMake(100, 170, 100,30); 


    UIImage *cbutton = [UIImage imageNamed:@"pdficon_small.png"]; 
    [button setImage:cbutton forState:UIControlStateNormal]; 
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [button2 addTarget:self 
       action:@selector(openWordings:) 
    forControlEvents:UIControlEventTouchDown]; 


    [button setTag:2]; 
    [self.view addSubview:button]; 

अग्रिम धन्यवाद।

उत्तर

14

मुझे लगता है कि आपका मतलब है कि button के आसपास एक सीमा है। यह इस

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 

क्या आप अभी क्या कर रहे हैं एक मानक RoundedRect बटन पैदा कर रही है, तो शीर्ष पर एक छवि रखने के साथ लाइन

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 

की जगह को निकालने के लिए। UIButtonTypeCustom का उपयोग करके अनिवार्य रूप से एक "खाली" बटन तैयार करेगा, जिससे आप अपनी छवि का उपयोग कर सकते हैं।

2

मैं एक xib फ़ाइल का उपयोग कर रहा हूं जो डिफ़ॉल्ट आईओएस 7 बटन का उपयोग करता है। मैं उन्हें तब तक पसंद करता हूं जब तक कि उपयोगकर्ता आईओएस 6 पर न हो - तब वे बदसूरत आईओएस 6 गोल बटन के साथ हिट हो जाते हैं। यह एक पूर्ण हैक है, लेकिन मेरी समस्याओं का समाधान किया। यह सिर्फ उपस्थिति के मुखौटा बटन के प्रत्येक तरफ 4 परतों को सम्मिलित करता है।

- (void)maskUglyIos6Border:(UIButton *)button 
{ 
    CALayer *layer = [CALayer layer]; 
    // top layer 
    layer.frame = CGRectMake(0, 0, button.layer.frame.size.width, 5); 
    layer.backgroundColor = [UIColor whiteColor].CGColor; 
    [button.layer addSublayer:layer]; 

    // bottom layer 
    CALayer *layer2 = [CALayer layer]; 
    layer2.frame = CGRectMake(0, button.layer.frame.size.height - 5, button.layer.frame.size.width, 5); 
    layer2.backgroundColor = [UIColor whiteColor].CGColor; 
    [button.layer addSublayer:layer2]; 

    // left layer 
    CALayer *layer3 = [CALayer layer]; 
    layer3.frame = CGRectMake(0, 0, 5, button.layer.frame.size.height); 
    layer3.backgroundColor = [UIColor whiteColor].CGColor; 
    [button.layer addSublayer:layer3]; 

    // right layer 
    CALayer *layer4 = [CALayer layer]; 
    layer4.frame = CGRectMake(button.layer.frame.size.width - 5, 0, 5, button.layer.frame.size.height); 
    layer4.backgroundColor = [UIColor whiteColor].CGColor; 
    [button.layer addSublayer:layer4]; 

} 

iOS7 उपस्थिति के साथ रखने के लिए, मैं प्रकाश डाला अक्षम और बजाय showsTouchWhenHighlighted का उपयोग कर की सिफारिश करेंगे।

1

चूंकि मैं एक सादे सफेद पृष्ठभूमि का उपयोग करता हूं, यह मेरे लिए हल करता है। मैं UIButton से उत्तराधिकारी हूं इसलिए मैं इसे स्टोरीबोर्ड का उपयोग करके आसानी से असाइन कर सकता हूं।

@implementation MyButton 

- (id)initWithFrame:(CGRect)frame 
{ 
self = [super initWithFrame:frame]; 
if (self) { 
    // adjust buttons -> "remove" border if we don't run on ios 7 
    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { 
     [self setBackgroundColor:[UIColor whiteColor]]; 
    } 

} 
return self; 

}