Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to change background color on UICollectionView (iOS)

I'm writing my first iOS app and I seam to be having some problems in changing the backgroundColor of a UICollectionView.

The app has a navigation controller and certain views. Initially, I was able to change the color in my AppDelegate implementation file:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];

        feedsList = [[FeedsListTVC alloc] init];

        rootNC = [[RootNC alloc] init];
        rootNC.viewControllers = [NSMutableArray arrayWithObjects:feedsList, nil];

        self.window.rootViewController = rootNC;

        return YES;
    }

Using

    self.window.backgroundColor = [UIColor whiteColor];

I was able to change the background color on all my views. However, I decided to add one more view (the UICollectionView) and to set it as the main view. So I changed the AppDelegate to this:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];

        CollectionViewLayoutCVL *collectionViewLayout = [[CollectionViewLayoutCVL alloc] init];
        self.viewController = [[MainViewControllerCVC alloc] initWithCollectionViewLayout:collectionViewLayout];

        rootNC = [[RootNC alloc] init];
        rootNC.viewControllers = [NSMutableArray arrayWithObjects:viewController, nil];

        self.window.rootViewController = rootNC;

        return YES;
    }

From my point of view this looks mostly the same.

I also tried this inside the implementation file of the UICollectionView but this changes the color of the view controller not the color of the Collection's view as far as I can tell:

    self.view.backgroundColor = [UIColor whiteColor]; 

Any ideas?

like image 916
daydr3am3r Avatar asked Jul 22 '14 13:07

daydr3am3r


2 Answers

self.collectionView.backgroundColor = [UIColor yourColor];

Hope this helps

like image 165
Saheb Roy Avatar answered Nov 19 '22 07:11

Saheb Roy


UIView *redView = [UIView new];
redView.backgroundColor = [UIColor redColor];
_collectionView.backgroundView = redView;
like image 21
Desert Rose Avatar answered Nov 19 '22 06:11

Desert Rose