InAppSettingsKitでUITableViewのスタイルを設定していて、ヘッダータイトルの色を変更したい:
ラベルWithout title
とText Field
は白である必要があります。これはどのように行うことができますか?
ありがとう。
InAppSettingsKitでUITableViewのスタイルを設定していて、ヘッダータイトルの色を変更したい:
ラベルWithout title
とText Field
は白である必要があります。これはどのように行うことができますか?
ありがとう。
これは古い質問ですが、答えを更新する必要があると思います。
この方法では、独自のカスタムビューを定義および作成する必要はありません。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/
Swift 5.0:
func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
if let header = view as? UITableViewHeaderFooterView {
header.textLabel?.textColor = .white
}
}
tableView:viewForHeaderInSection:
tableViewControllerにメソッドを実装します。これにより、ヘッダーに独自のビューを提供できるようになります。これには、必要なフォーマットのUILabelを含めることができます。
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UILabel *customLabel = [[UILabel alloc] init];
customLabel.text = [self tableView:tableView titleForHeaderInSection:section];
return customLabel;
}
ラベルフレームは、セクションの間隔を空けるのに十分な高さに設定することを忘れないでください。より大きなUIView内にラベルを埋め込み、代わりにそれを返すことで、配置を簡素化することができます(たとえば、ラベルの左パディングを増やしたい場合)。
これをSwiftに「変換」するのに数分かかりましたが、これはSwift 1.2(iOS 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()
}
私はこれを見つけました: iPhone SDKのグループ化されたTableViewのセクションヘッダーのテキストの色を変更するにはどうすればよいですか? それはおもてなしをします、そして私はそれを@rishiによる答えのリンクからの少しのコードと組み合わせました、そしてそれは私の人生をとても楽にしてくれました!! ラベルビューの調整を少し調整する必要がありましたが、それは魅力のように機能しました。
Swift 4バージョン:
func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
guard let headerView = view as? UITableViewHeaderFooterView else { return }
headerView.textLabel?.textColor = .red // any color
}
テーブルセルの作成方法で次のコード行を試すことができます-
cell.textLabel.backgroundColor = //Your color;
cell.detailTextLabel.backgroundColor = //Your color;
詳細な説明については、以下を参照してください。ここでは、言及したものと同様のカスタムセクションテーブルを作成する詳細な例を見つけることができます-http: //undefinedvalue.com/2009/08/25/changing-background-color-and-section -header-text-color-grouped-style-uitableview