私のiPhoneアプリケーションでは、私のUITableViewのヘッダーを変更したいと思います。灰色のデフォルトのヘッダーと同じグラデーション/アルファ/ニースのスタイルを維持するにはどうすればいいですか?そして、例えば勾配 を描画するためにCoreGraphicsを使用します。UITableViewヘッダー - iPhone
答えて
を使用することができます
- (void) drawRect:(CGRect)rect
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGGradientRef glossGradient;
CGColorSpaceRef rgbColorspace;
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1 };
const CGFloat *startColorComponents = CGColorGetComponents(startColor.CGColor);
const CGFloat *endColorComponents = CGColorGetComponents(endColor.CGColor);
CGFloat components[8] = { startColorComponents[0], startColorComponents[1], startColorComponents[2], startColorComponents[3], // Start color
endColorComponents[0], endColorComponents[1], endColorComponents[2], endColorComponents[3] }; // End color
rgbColorspace = CGColorSpaceCreateDeviceRGB();
glossGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);
CGRect currentBounds = self.bounds;
CGPoint topCenter = CGPointMake(CGRectGetMidX(currentBounds), 0.0f);
CGPoint bottomCenter = CGPointMake(CGRectGetMidX(currentBounds), CGRectGetMidY(currentBounds));
CGContextDrawLinearGradient(currentContext, glossGradient, topCenter, bottomCenter, 0);
CGGradientRelease(glossGradient);
CGColorSpaceRelease(rgbColorspace);
}
次に、Sachinの提案に従いますが、代わりにカスタム表示クラスを使用してください。
bottomCenterでCGRectGetMidY(currentBounds)が使用されている理由がわかりません。私はあなたが望んでいるのは実際には下のYであり、Yの半ばではないと思う。私はこれを全高に変更し、それはもっと良く働いた。それ以外はこれは素晴らしいです。 – clarky
あなたはグラデーションを適用したい場合は、カスタムビュークラスを作成し、その後のdrawRectをオーバーライドすることができ、この
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectZero];
headerView.backgroundColor = [UIColor lightGrayColor];
return headerView;
}
。それはtableViewヘッダーの見栄えを削除し、タイトルが削除されました – CodeGuy
フレームが設定されていないので、動作しません。 –
- 1. UITableViewヘッダーの問題
- 2. iPhone - UITableViewのiAds
- 3. iphone、UITableField in UITableView
- 4. iPhone UITableView、UINavigationView、Interface Builder
- 5. UITableViewヘッダー内のページコントロール。 swift
- 6. スウィフト - 私はリロードのUITableViewヘッダー
- 7. UITableViewヘッダー/フッターを取得
- 8. iPhone AdMob UITableViewの問題
- 9. 複数チョイスiPhoneアプリ - UITableView?
- 10. iphone - UITableViewのスクロールの問題
- 11. iphone sqliteデータiOS4のuitableview
- 12. iPhoneアプリケーションのUITableviewのxmlデータ
- 13. iPhone用のカスタムUITableViewテキスト
- 14. iPhone UITableViewセクションを作成
- 15. カスタム削除ボタンuitableview iphone sdk
- 16. UITableView detailTextLabel - iphoneの開発
- 17. iphone sdkのUITableView LoadMoreオプション
- 18. UITableViewヘッダーをスクロールしますか?
- 19. iOS10 - UITableViewヘッダーのUIButtonのContentViewブロッキングタッチ
- 20. UITableViewのタイトル/ヘッダーをロックするには
- 21. UITableViewヘッダーUITableViewAutomaticDimensionが機能しない
- 22. uitableviewヘッダーのテキストを更新します。
- 23. NSFetchedResultsControllerからUITableViewヘッダーを設定する
- 24. テーブルビューでヘッダーのクリックを検出する方法uitableview
- 25. iPhone UITableView "More" Cell?実装方法
- 26. iphoneでUITableViewを更新するには?
- 27. UITableViewにUILabelを追加する - iphone
- 28. UITableVIewのHTMLコンテンツに関するIPhone
- 29. iPhone、UITableViewの行アイコン/ボタンのサイズは?
- 30. iPhone上でUITableViewを使用したポップアップモーダル
私は、これはあなたを助けることができると思う:動作しませんでした http://stackoverflow.com/questions/813068/uitableview-change-section-header-color – Peres