के साथ नीचे दिए गए शीर्ष पर लेबल के साथ UIButton (UIButtonTypeCustom) बनाना और मैं & छवि (परिपत्र दिखाना है) के नीचे एक टेक्स्ट (सिंगल/मल्टी लाइन) के साथ बटन प्रदर्शित करने का प्रयास कर रहा हूं। शीर्ष; छवि पर & टेक्स्ट को हाइलाइट किया जाना चाहिए। इस तरह:ऑटोलायआउट
यहाँ viewDidLoad
में कोड है:
btArtAndPainting = [UIButton buttonWithType:UIButtonTypeCustom];
btArtAndPainting.backgroundColor = [[UIColor cyanColor] colorWithAlphaComponent:1.00f];
btArtAndPainting.translatesAutoresizingMaskIntoConstraints = NO;
self.vwContainer.translatesAutoresizingMaskIntoConstraints = NO;
[self.vwContainer addSubview:btArtAndPainting];
[btArtAndPainting setImage:[UIImage imageNamed:kIMGCategoryArtAndPaintingNormal] forState:UIControlStateNormal];
[btArtAndPainting setImage:[UIImage imageNamed:kIMGCategoryArtAndPaintingHighlighted] forState:UIControlStateHighlighted];
[btArtAndPainting setTitle:@"Art and Painting" forState:UIControlStateNormal];
[btArtAndPainting setTitle:@"Art and Painting" forState:UIControlStateHighlighted];
btArtAndPainting.tintColor = [UIColor redColor];
btArtAndPainting.titleLabel.font = [UIFont systemFontOfSize:10.00f];
btArtAndPainting.titleLabel.textColor = [UIColor whiteColor];
btArtAndPainting.titleLabel.textAlignment = NSTextAlignmentCenter;
btArtAndPainting.titleLabel.lineBreakMode = NSLineBreakByWordWrapping | NSLineBreakByTruncatingTail;
btArtAndPainting.titleLabel.numberOfLines = 0;
btArtAndPainting.imageEdgeInsets = UIEdgeInsetsMake(0.00f, 8.00f, 20.00f, 8.00f);
btArtAndPainting.titleEdgeInsets = UIEdgeInsetsMake(32.00f, 0.00f, 0.00f, 0.00f);
NSArray *constraintsWidth = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[btArtAndPainting(60)]|"
options:0
metrics:nil
views:viewDictionary];
NSArray *constraintsHeight = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[searchBar]-10-[btArtAndPainting(60)]"
options:0
metrics:nil
views:viewDictionary];
[self.vwContainer addConstraints:constraintsHeight];
[self.vwContainer addConstraints:constraintsWidth];
[btArtAndPainting layoutIfNeeded];
[btArtAndPainting needsUpdateConstraints];
समस्या है कि पाठ सब पर प्रदर्शित नहीं किया जाता है (दोनों सामान्य & प्रकाश डाला राज्यों में) है। नीचे लिंक्ड छवियों को देखें। टेक्स्ट के लिए जगह बनाने के लिए मैं UIEdgeInset का उपयोग कैसे करूं? मैंने UIButton
श्रेणी बनाने की भी कोशिश की है लेकिन प्रभाव उतना ही कम है।
आप को संशोधित करते हैं एक ** UIButton **, मैं दृढ़ता से आप बनाने ** CustomView ** –
@grhnkdlk सलाह मुझे लगता है कि आवश्यकता नहीं होगी। क्या आप कृपया मुझे बता सकते हैं कि मेरे उपयोग के मामले में इसका क्या फायदा है? – Smarto
** UIButton ** में संशोधन करना मुश्किल है, लेकिन कस्टमव्यूज़ अधिक लचीला और नि: शुल्क है। मेरे लिए आपका समाधान है * कस्टमव्यू * –