असल में मैं अपने सेक्शन हेडर का फ़ॉन्ट और रंग बदलना चाहता हूं, इसलिए मैं tableVieW:viewForHeaderInSection
लागू करता हूं। सबसे पहले मैं इस कोड की कोशिश की:tableVieW क्यों है: viewForHeaderInSection मेरे UILabel की फ्रेम प्रॉपर्टी को अनदेखा करता है?
-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel* headerLabel = [[[UILabel alloc] init] autorelease];
headerLabel.frame = CGRectMake(10, 0, 300, 40);
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.textColor = [UIColor blackColor];
headerLabel.font = [UIFont boldSystemFontOfSize:18];
headerLabel.text = @"My section header";
return headerLabel;
}
लेकिन किसी कारण फ्रेम संपत्ति नजरअंदाज कर दिया है के लिए (मैं बाईं तरफ 10px इनसेट के बारे में बात कर रहा हूँ)। अब मैं निम्नलिखित का उपयोग करता हूं:
-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView* headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)] autorelease];
UILabel* headerLabel = [[UILabel alloc] init];
headerLabel.frame = CGRectMake(10, 0, 300, 40);
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.textColor = [UIColor blackColor];
headerLabel.font = [UIFont boldSystemFontOfSize:18];
headerLabel.text = @"My section header";
[headerView addSubview:headerLabel];
[headerLabel release];
return headerView;
}
वांछित परिणाम के साथ। क्या कोई मुझे समझा सकता है कि दूसरा दृष्टिकोण क्यों काम करता है और पहला नहीं करता है?
पी एस। दोनों ही मामलों में मैं tableView:heightForHeaderInSection
रूप में अच्छी तरह लागू, लौटने 40.0
फिर मुझे इस कोड को प्राप्त करने के लिए वास्तव में मेरे कोड में "हेडर व्यू" की आवश्यकता है, है ना? – phi
हां, आपको इसकी आवश्यकता है :) – Jilouc
ग्रेट, धन्यवाद :) – phi