我在使用一些諮詢代碼的UITableView上創建簡單的漸變時遇到了問題。當點擊一個按鈕時,會顯示一個彈出窗口。在popover中,我有一個navigationController,它的rootViewController是我的自定義類。我的類有這些屬性UITableView的漸變背景
@interface TargetDetailView : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
CGGradientRef backgroundGradient;
UITableView *_targetTableView;
}
@property (retain, nonatomic) IBOutlet UIGradientView *backgroundView;
@property (nonatomic, retain) IBOutlet UITableView *TargetTableView;
在viewDidLoad中
,我這樣做:backgroundView設置爲[UIColor clearColor]
CGColorSpaceRef gray = CGColorSpaceCreateDeviceGray();
backgroundGradient = CGGradientCreateWithColors(gray, (CFArrayRef)[NSArray arrayWithObjects:(id)[[UIColor colorWithWhite:70./255 alpha:1] CGColor], (id)[[UIColor colorWithWhite:35./255 alpha:1] CGColor], nil], nil);
CGColorSpaceRelease(gray);
[self.backgroundView setGradient:backgroundGradient];
我的細胞。另外,我在IB的tableView的背景也設置爲[UIColor clearColor]
。然而,當我展示我的popover時,我沒有看到漸變。在IB中,層次結構是類的.view屬性,然後是backgroundView插座,以及該視圖內的UITableView。
我試過其他的東西來排除故障,如完全擺脫gradientView,並將tableView作爲類的.view屬性中的唯一項。然後我試試self.backgroundColor = [UIColor orangeColor];
我看不到任何顏色。一切看起來都是灰色的。我究竟做錯了什麼?謝謝。
即使我給索引零(0)..子層出現在頂部..我該怎麼做..? – sakthig 2013-02-26 09:15:01
請把你的代碼的一部分,有很多情況可能會導致這種問題 – 2013-03-08 02:17:35
我這樣做來克服這個問題'UIView * tableBackgroundView = [[UIView alloc] init]; [tableBackgroundView.layer insertSublayer:gLayer atIndex:1]; [tableView setBackgroundView:tableBackgroundView];'..現在它工作正常;) – sakthig 2013-03-08 05:29:32