2017-01-25 3 views
-1

UITableViewCellが占有するビューに背景色を設定しようとしています。私は出口をドラッグ、私はそれダイナミックセルでビュー(UITableview)の背景を設定する方法は?

extension CAGradientLayer{ 
func viewGradient(topColour:UIColor,bottomColour : UIColor) -> CAGradientLayer{ 
    let gradientColor: [CGColor] = [topColour.cgColor, bottomColour.cgColor] 
    let gradientLocations: [Float] = [0.0/1.0] 
    let gradientLayer: CAGradientLayer = CAGradientLayer() 
    gradientLayer.colors = gradientColor 
    gradientLayer.locations = gradientLocations as [NSNumber]? 

    return gradientLayer 
    } 
} 

に戻り傾斜層を有していて、私は、ビューコントローラの私のviewDidLoad方法でこのメソッドにアクセスしている

let bottomColour = UIColor(red: (0.018), green: (0.38), blue: (0.64), alpha: 1.0) 
let topColour = UIColor(red: (0.13), green: (0.63), blue: (0.67), alpha: 0.7) 
let background = CAGradientLayer().viewGradient(topColour:topColour,bottomColour : bottomColour) 
background.frame = self.view.bounds 
self.view.layer.insertSublayer(background, at: 0) 
myMenu.layer.insertSublayer(background, at: 0) 

私はテーブルビューの動的細胞を有しますセルの数が増えるにつれてビューのスライドが下がり、セルを見るためにスクロールする必要があります。空白があります。背景のグラデーションカラーを持つようにスクロール領域全体を設定する方法はありますか、何か不足していますか?

Here is the screenshot of the images showing my exact problem

+0

'UITableView'は固定ビューを背後に置く' backgroundView'プロパティを持っています。 –

答えて

1

としてはUITableViewbackgroundView性質を有する、上記のコメント。あなたのviewDidLoad方法で

として宣言あなたbackgroundを一定に保つには、[追加下回る、次のとおりです。

self.tableView.backgroundView = background

お役に立てば幸いです。

+0

ありがとう、それは完全に動作します。 –

関連する問題