मैं InAppSettingsKit में UITableView स्टाइल हूँ और हैडर शीर्षक का रंग बदलना चाहते हैं:UITableView परिवर्तन शीर्ष शीर्षक रंग
लेबल Without title
और Text Field
सफेद होना चाहिए। यह कैसे किया जा सकता है?
धन्यवाद।
मैं InAppSettingsKit में UITableView स्टाइल हूँ और हैडर शीर्षक का रंग बदलना चाहते हैं:UITableView परिवर्तन शीर्ष शीर्षक रंग
लेबल Without title
और Text Field
सफेद होना चाहिए। यह कैसे किया जा सकता है?
धन्यवाद।
आप तालिका सेल निर्माण विधि में कोड की निम्न पंक्ति कोशिश कर सकते हैं -
cell.textLabel.backgroundColor = //Your color;
cell.detailTextLabel.backgroundColor = //Your color;
आप और अधिक विस्तार वर्णन है, जहां आप कस्टम sectioned तालिका आप क्या उल्लेख किया है के समान बनाने का विस्तार उदाहरण मिल सकता है के लिए निम्नलिखित उल्लेख कर सकते हैं - http://undefinedvalue.com/2009/08/25/changing-background-color-and-section-header-text-color-grouped-style-uitableview
tableViewController में tableView:viewForHeaderInSection:
विधि को लागू करें। इससे आपको हेडर के लिए अपना खुद का दृश्य प्रदान करने की अनुमति मिल जाएगी, जिसमें यूआईएलएबल शामिल हो सकता है जो आप चाहते हैं कि प्रारूपण, उदाहरण के लिए
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UILabel *customLabel = [[UILabel alloc] init];
customLabel.text = [self tableView:tableView titleForHeaderInSection:section];
return customLabel;
}
लेबल फ्रेम को अनुभागों के बाहर स्थान के लिए पर्याप्त लंबा सेट करना याद रखें। आप लेबल को एक बड़े UIView के अंदर एम्बेड करना चाहते हैं और इसके बजाय स्थिति को सरल बनाने के लिए वापस लौटना चाहते हैं (उदाहरण के लिए यदि आप लेबल पर बाएं-पैडिंग को बढ़ाएं)।
यह एक रिसाव है। रिलीज या autorelease कस्टम लेबल। – stephen
मुझे लगता था कि वह एआरसी का उपयोग कर रहा था। –
मैं इस पाया: How to change text color for Section Headers in a Grouped TableView in iPhone SDK? यह एक का इलाज काम करता है, और मैं @rishi द्वारा जवाब में लिंक से कोड का एक छोटा सा के साथ संयुक्त, और यह मेरे जीवन इतना आसान बना दिया !! हालांकि मुझे लेबल दृश्य के समन्वय को थोड़ा सा ट्विक करना पड़ा, लेकिन यह एक आकर्षण की तरह काम करता था।
यह एक पुराना सवाल है, लेकिन मुझे लगता है कि उत्तर को अद्यतन करने की आवश्यकता है।
इस विधि में आपके स्वयं के कस्टम व्यू को परिभाषित करने और बनाने में शामिल नहीं है। iOS 6 में और ऊपर, आप आसानी से
-(void)tableView:(UITableView *)tableView
willDisplayHeaderView:(UIView *)view
forSection:(NSInteger)
प्रतिनिधि विधि को परिभाषित करते हुए पृष्ठभूमि रंग और पाठ का रंग बदल सकते हैं।
उदाहरण के लिए:
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
// Background color
view.tintColor = [UIColor blackColor];
// Text Color
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
[header.textLabel setTextColor:[UIColor whiteColor]];
// Another way to set the background color
// Note: does not preserve gradient effect of original header
// header.contentView.backgroundColor = [UIColor blackColor];
}
मेरी पोस्ट यहाँ से लिया: https://happyteamlabs.com/blog/ios-how-to-customize-table-view-header-and-footer-colors/
अच्छी नौकरी, जिस तरह से यह विधि अभी भी आईओएस 7 में काम करती है, वैसे भी किया जाता है। –
यह कोड आईओएस 7 के साथ "बस काम करता है" में छोड़ देता है। अच्छा। – russes
अब तक का बेहतर उत्तर। –
यह मेरे स्विफ्ट को यह "अनुवाद" करने के लिए कुछ मिनट लग गए, लेकिन यहां स्विफ्ट 1.2 (आईओएस 8 में एक काम बराबर है)। सुनिश्चित करें और UITableViewDelegate
को अपनी कक्षा में लागू करें:
// MARK: - VIEW METHODS
override func viewDidLoad() {
tableView.delegate = self
}
// MARK: - TABLEVIEW DELEGATE METHODS
override func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
let header = view as! UITableViewHeaderFooterView
header.textLabel.textColor = UIColor.whiteColor()
}
मैं अनुभाग के शीर्षक को सेल लेबल नहीं बदलना चाहता हूं। –
का अर्थ तालिका अनुभाग का शीर्षलेख है। – rishi
हां, मेरा मतलब हेडर लेबल था। –