Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-14-2011, 07:25 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 57
Conor.Higgins is on a distinguished road
Default Adding dynamic elements UIView subclass to UIView, UIScrollView, etc

Hi I was wondering if anyone has come across any good tutorials or guides for adding dynamic UIView subclasses to other uiviews and uiscrollviews?

I am working on an app at the moment which requires a couple of uiview subclasses which I then need to be able to generate on the fly and add to a uiview.

For example, I need to generate an anagram view in one area of the application. This will require me to create some drag and drop views, each of which will correspond to a single letter. If anyone has any ideas as to how I can achieve this. I have created a subclass for a single letter, and had hoped to build it using a simple label and a graphic behind the letter which will highlight whether or not it is correct.

I have an IBAction hooked up to a button and it processes this code:

Code:
AnagramLetter *test = [[AnagramLetter alloc] init];
    [letterHolder addSubview:test];
I know that this is being processed as I have added a couple of NSLogs to check whether or not the label etc is being processed properly:


Code:
@implementation AnagramLetter

@synthesize testLbl;

- (id)initWithFrame:(CGRect)frame
{
    frame = CGRectMake(20, 55, 100, 100);
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        NSLog(@"I exist");
        testLbl = [[UILabel alloc] init];
        [testLbl setText:@"Text should now be set"];
        [self addSubview:testLbl];
        NSLog(@"this is the label's value: %@",testLbl.text);
    }
    return self;
}
The logs are being output, however it is not showing up on the application screen, or seemingly is not being added to the letterHolder UIView object properly.

Any ideas?

Conor

Conor
Conor.Higgins is offline   Reply With Quote
Old 11-14-2011, 07:31 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 57
Conor.Higgins is on a distinguished road
Default

Quote:
Originally Posted by Conor.Higgins View Post
Hi I was wondering if anyone has come across any good tutorials or guides for adding dynamic UIView subclasses to other uiviews and uiscrollviews?

I am working on an app at the moment which requires a couple of uiview subclasses which I then need to be able to generate on the fly and add to a uiview.

For example, I need to generate an anagram view in one area of the application. This will require me to create some drag and drop views, each of which will correspond to a single letter. If anyone has any ideas as to how I can achieve this. I have created a subclass for a single letter, and had hoped to build it using a simple label and a graphic behind the letter which will highlight whether or not it is correct.

I have an IBAction hooked up to a button and it processes this code:

Code:
AnagramLetter *test = [[AnagramLetter alloc] init];
    [letterHolder addSubview:test];
I know that this is being processed as I have added a couple of NSLogs to check whether or not the label etc is being processed properly:


Code:
@implementation AnagramLetter

@synthesize testLbl;

- (id)initWithFrame:(CGRect)frame
{
    frame = CGRectMake(20, 55, 100, 100);
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        NSLog(@"I exist");
        testLbl = [[UILabel alloc] init];
        [testLbl setText:@"Text should now be set"];
        [self addSubview:testLbl];
        NSLog(@"this is the label's value: %@",testLbl.text);
    }
    return self;
}
The logs are being output, however it is not showing up on the application screen, or seemingly is not being added to the letterHolder UIView object properly.

Any ideas?

Conor

Conor
I just added this line and it seems as though the view is being added:

Code:
self.backgroundColor = [UIColor blackColor];
however I can't seem to get the label to show properly. Do I need to initialize the label in any way?
Conor.Higgins is offline   Reply With Quote
Old 11-14-2011, 08:07 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 57
Conor.Higgins is on a distinguished road
Default progress, but still not working properly

I have made some progress, but the label is still not acting as it should be. For some reason I can't seem to get the label to resize itself properly.

I have changed the init method around to now be:

Code:
- (id)initWithFrame:(CGRect)frame
{
    frame = CGRectMake(0, 0, 100, 100);
    CGRect lblFrame = CGRectMake(0, 0, 100,100);
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        testLbl = [[UILabel alloc] initWithFrame:lblFrame];
        testLbl.backgroundColor = [UIColor clearColor];
        testLbl.textColor = [UIColor darkGrayColor];
        testLbl.textAlignment = UITextAlignmentCenter;
        [testLbl setText:@"T"];
        testLbl.numberOfLines = 1;
        testLbl.minimumFontSize = 50;
        testLbl.adjustsFontSizeToFitWidth = YES;
        [self addSubview:testLbl];
    }
    return self;
}
Even though I specifically stating above that the UILabel should be of a minimum font size 50, and that it should fit itself to the frame properly otherwise, it is showing up as though it were a size 10 or 11 font.

Any ideas?

Conor
Conor.Higgins is offline   Reply With Quote
Old 11-17-2011, 11:07 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 57
Conor.Higgins is on a distinguished road
Default Bump

Bump. Any ideas? My deadline is quickly approaching unfortunately
Conor.Higgins is offline   Reply With Quote
Reply

Bookmarks

Tags
anagram, dynamic, subclass, uiview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 394
17 members and 377 guests
7twenty7, Alex-alex, Apptronics RBC, baja_yu, chiataytuday, dre, gwelmarten, ipodphone, jeroenkeij, jleannex55, matador1978, mbadegree, n00b, pbart, QuantumDoja, Retouchable, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:24 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0