Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8781303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:15:58+00:00 2026-06-13T20:15:58+00:00

It is my first time that I want to create a UICollectionView. This is

  • 0

It is my first time that I want to create a UICollectionView. This is how I want it to look like:

enter image description here

I read some tutorials and I know how it works exactly. The thing is as you see in the image, The UICollection cells have border from up, bottom, left and right. Do you know how can set these kind of border in Collection View?

As you see two of the items are selected by red color. is it possible in UICollectionView to have multiple selected items? if yes, could you please give send me some tutorials.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:16:00+00:00Added an answer on June 13, 2026 at 8:16 pm

    Small example project here: https://github.com/erikt/ETMultiSelect

    First you have to make it possible to select more than one cell in the UICollectionView. This is done by setting the allowsMultipleSelectionproperty to YES on the collection view.

    The view controller would look something like this:

    #import "ETViewController.h"
    #import "ETCellView.h"
    
    @implementation ETViewController
    
    static NSString *cellIdentifier = @"cvCell";
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        // Register our custom collection view cell
        [self.collectionView registerClass:ETCellView.class forCellWithReuseIdentifier:cellIdentifier];
    
        // Make it possible to select multiple cells
        self.collectionView.allowsMultipleSelection = YES;
    }
    
    #pragma mark - UICollectionViewDataSource
    - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
        return 1;
    }
    
    - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
        return 10;
    }
    
    #pragma mark - UICollectionViewDelegate
    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
        ETCellView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
        return cell;
    }
    
    @end
    

    The UICollectionViewCell is made up of several views. It has a content view, a background view and a selected background view.

    There are many ways to achieve something similar to your picture, but I set the border on the selected background layer and add a subview to the content view that’s inset so the background border is visible:

    #import "ETCellView.h"
    #import <QuartzCore/QuartzCore.h>
    
    @implementation ETCellView
    
    - (id)initWithFrame:(CGRect)frame {
        self = [super initWithFrame:frame];
        if (self) {
            self.restorationIdentifier = @"cvCell";
            self.backgroundColor = [UIColor clearColor];
            self.autoresizingMask = UIViewAutoresizingNone;
    
            CGFloat borderWidth = 3.0f;
            UIView *bgView = [[UIView alloc] initWithFrame:frame];
            bgView.layer.borderColor = [UIColor redColor].CGColor;
            bgView.layer.borderWidth = borderWidth;
            self.selectedBackgroundView = bgView;
    
            CGRect myContentRect = CGRectInset(self.contentView.bounds, borderWidth, borderWidth);
    
             UIView *myContentView = [[UIView alloc] initWithFrame:myContentRect];
             myContentView.backgroundColor = [UIColor whiteColor];
             myContentView.layer.borderColor = [UIColor colorWithWhite:0.5f alpha:1.0f].CGColor;
             myContentView.layer.borderWidth = borderWidth;
             [self.contentView addSubview:myContentView];
         }
         return self;
    }
    
    @end
    

    The result is something like this:

    iPhone screen shot

    Clone and play with the sample project.

    In a real project you would want to keep track of what the user has selected in the view controller, by adding the selected data model entities to some structure (like a NSMutableArray) in the – collectionView:didSelectItemAtIndexPath: method on the UICollectionViewDelegate protocol.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the first time I have attempted to create a .dll, that will
I want to create a view that will appear only once (on first time).
I have 2 pages that I want to show as instructions the first time
This is my first time that I use WCF and Android. So, sorry for
I have a database that is currently sharded. This is the first time that
That's my first time posting on stackoverflow. I've been finding usefull answers on this
I am trying android programming for the first time and want to create a
I want to create an XML file from java 6 (it's the first time
I am using some of these tools for the first time. I have read
I want to create a map at compile time that maps compile time keys

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.