ios - I couldn't draw fully gradient background on iPad -


i drew gradient background layer on uicollectionview following code.

cagradientlayer* collectionradient = [cagradientlayer layer]; collectionradient.bounds = self.collectionview.bounds; collectionradient.anchorpoint = cgpointzero; collectionradient.colors = [nsarray arraywithobjects:(id)[startcolor cgcolor],(id)[endcolor cgcolor], nil]; uiview* vv = [[uiview alloc] init]; self.collectionview.backgroundview = vv; [self.collectionview.backgroundview.layer insertsublayer:collectionradient atindex:0]; 

it works on iphone simulator. not ipad. below image that. background layer taking part of uicollectionview.

enter image description here

i suggest creating subclass of uiview named gradientview or similar use background view.

in implementation of gradientview need overload following class method:

+ (class)layerclass  {     return [cagradientlayer class]; } 

then, change code above following:

uiview* backgroundview = [[gradientview alloc] initwithframe:self.collectionview.bounds]; backgroundview.autoresizingmask = (uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleheight); self.collectionview.backgroundview = backgroundview; cagradientlayer* collectiongradient = (cagradientlayer *)backgroundview.layer; collectiongradient.anchorpoint = cgpointzero; collectiongradient.colors = [nsarray arraywithobjects:(id)[startcolor cgcolor],(id)    [endcolor cgcolor], nil]; 

i'm hoping custom gradientview's layer automatically resize. if not, may need implement layoutsubviews method in custom gradientview resize gradient layer.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -