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 7858237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:20:01+00:00 2026-06-02T21:20:01+00:00

I’ve subclassed UIView so I can add multiple view of the same type to

  • 0

I’ve subclassed UIView so I can add multiple view of the same type to my project. The view is basically a rectangle with a radius, a picture in the left side and a piece of text on the right. Now don’t get me wrong the code bellow works and all but i’m always asking myself “is this the way, or am I getting it really wrong”.

1) I’m mixing CALayers with UILabels, is this ok?

2) Is the setUpView the way its done.

3) If this is ok, whats my best bet for letting the imageLayer respond to touch events?

4) Could I just ask a side question as well. As a part time beginner with only one basic app in the store am I been a bit picky. What I mean is, should I just make it work and crack on! What do you think?

@synthesize dateLabel = _dateLabel;
@synthesize nameLabel = _nameLabel;
@synthesize photo = _photo;
@synthesize roundRect= _roundRect;
@synthesize imageLayer = _imageLayer;



-(void)setUpView
{

    //create the white rectangle
        self.roundRect.frame = CGRectMake(0.0, 0.0, self.frame.size.width, self.frame.size.height);
    self.roundRect.cornerRadius = 15.0;
    self.roundRect.backgroundColor = [UIColor clearColor].CGColor;
    self.roundRect.borderColor = [UIColor whiteColor].CGColor;
    self.roundRect.borderWidth = 2.0;
    self.roundRect.masksToBounds = YES;

   //create the photo 
   CGImageRef image = [self.photo CGImage];
    self.imageLayer.frame = CGRectMake(0.0, 0.0, self.roundRect.frame.size.width*0.48, self.roundRect.frame.size.height);
    self.imageLayer.borderColor = [UIColor whiteColor].CGColor;
    self.imageLayer.borderWidth = 2.0;
    self.imageLayer.masksToBounds = YES;
   [self.imageLayer setContents:(__bridge id)image];
   [self.imageLayer setContentsGravity:kCAGravityResizeAspectFill];
    [self.imageLayer setContentsRect:CGRectMake(0.0,0.0,1.1,1.0)];

    //create label
    self.nameLabel.frame = CGRectMake(self.imageLayer.frame.size.width+5, self.roundRect.frame.size.height*0.05, self.roundRect.frame.size.width*0.48,self.roundRect.frame.size.height*0.35);
    self.nameLabel.backgroundColor = [UIColor clearColor];
    self.nameLabel.textAlignment = UITextAlignmentCenter;
    self.nameLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
    self.nameLabel.textColor = [UIColor whiteColor];
    self.nameLabel.adjustsFontSizeToFitWidth =YES;

    self.nameLabel.font = [UIFont fontWithName:@"Gill Sans" size:50.0];








    [self.roundRect addSublayer:self.imageLayer];
    [self.layer addSublayer:self.roundRect];
    [self addSubview:self.nameLabel];

}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{


}

-(void)setPhoto:(UIImage *)photo
{
    _photo = photo;

    [self setUpView];

}

-(void)setNameLabel:(UILabel *)nameLabel
{
    _nameLabel = nameLabel;

    [self setUpView];

}


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.roundRect = [[CALayer alloc]init];
        self.imageLayer = [[CALayer alloc]init];
        self.nameLabel = [[UILabel alloc]init];


    [self setUpView];
    }
    return self;
}
  • 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-02T21:20:05+00:00Added an answer on June 2, 2026 at 9:20 pm

    You could make this easier by using the Interface Builder. I would create a XIB with a UIView set to the size I want. Then add a label (nameLabel) and configure it how you like. You can use QuartzCore layers cornerRadius to set your rounded corners. Then you can use your subclass in the XIB and set it as the class type for the UIView. Not the file owner but the view. Then you can link your label as an outlet and you won’t need to create it manually. You can remove some of the code above and still have your functionality and looks. I’ve learned to let the Interface Builder do the work when you can.

    Hope this helps.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.