Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 7    Views: 99

jorge10
Aspiring developer
Profile
Posts: 36
Reg: Aug 24, 2012
Barcelone
2,060
09/04/12 01:28 AM (13 years ago)

How to change the quiz start button?

Hi! I have been searching how to change the button to begin each quiz. It says "Start Quiz". I have found the code from MGoBlue, but it does not work properly for BT.2.0. for IOS. The new image button seems cut and the "Start quiz" letters still remains. Please, some idea? The code that MGoBlue gave was: Replace the code in the '//create rounded rectangle start button' with the following: //create rounded rectangle start button startButton = [UIButton buttonWithType:UIButtonTypeCustom]; //sets the type of UIButton UIImage *buttonBackgroundImage = [UIImage imageNamed:@'button.png']; UIImage *stretchedBackground = [buttonBackgroundImage stretchableImageWithLeftCapWidth:73 topCapHeight:0]; //startButton is declared as an instance variable UIButton in the interface [startButton setBackgroundImage:stretchedBackground forState:UIControlStateNormal]; [super viewDidLoad]; [self.view addSubview:startButton]; [startButton setFrame:CGRectMake(margin, answerButtonBoxTop + 5, answerButtonBoxWidth, buttonHeight)]; startButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; [startButton addTarget:self action:@selector(startQuiz) forControlEvents:UIControlEventTouchUpInside]; [startButton.titleLabel setFont:[UIFont boldSystemFontOfSize:30]]; [startButton setTitle:NSLocalizedString(@quizStart,@start quiz) forState:UIControlStateNormal]; [startButton.titleLabel setShadowColor:[UIColor blackColor]]; // OPTIONAL ADD DROP SHADOW [startButton.titleLabel setShadowOffset:CGSizeMake(0.0f, -1.0f)]; // OPTIONAL DROP SHADOW Remember to change the single quotes to double quotes around 'button.png' I'm using a button.png file that's 129px x 90px. If you look at that tutorial you'll see why I did this. The graphic can be stretched to work for both iphone and ipad screens.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/04/12 02:02 AM (13 years ago)
If all you're trying to do is change the size of the button, becuase it's getting cut off, adjust the frame. [startButton setFrame:CGRectMake(margin, answerButtonBoxTop + 5, answerButtonBoxWidth, buttonHeight)]; That line sets the "FRAME" for the button. The frame is a rectangular box around the button creating it's size. If it's getting cut-off, the fram is shorter or narrower than your image. Adjust the frame and experiement... [startButton setFrame:CGRectMake(50, 100, 200, 40)]; would put the button at "50 pixels from left, 100 pixels from top, 200 pixels wide and 40 pixels tall" It's x, y, width, height. Hope that helps.
 
jorge10
Aspiring developer
Profile
Posts: 36
Reg: Aug 24, 2012
Barcelone
2,060
like
09/04/12 04:36 AM (13 years ago)
Hi David! Thank you for your quick reply. Also, I appreciate the service you give with buzztouch. I will contribute in some way very soon. My problem is to change the word "start quiz" for another different spanish word. So, I don´t need to change the size of the button, I need to replace it with other word or even with an image. Please, some idea? Regards, Jorge
 
MGoBlue
Apple Fan
Profile
Posts: 980
Reg: Jun 07, 2011
Gold River, CA
10,600
like
09/04/12 06:16 AM (13 years ago)
Hello Jorge, To change the "start quiz" text, you do that in two places. In the Localizable.strings file. Find: "quizStart" = "start quiz"; And change "start quiz" to whatever you need. In BT_screen_quiz.m file, find: [startButton setTitle:NSLocalizedString(@"quizStart",@"start quiz") And change "start quiz" to match what you put in the localizable file. I don't remember the code I posted off hand. Following is code I'm using in one of my apps that works great (Note that this one also uses a custom font called Chalkduster): //startButton is declared as an instance variable UIButton in the interface [startButton setBackgroundImage:buttonBackgroundImage forState:UIControlStateNormal]; [super viewDidLoad]; [self.view addSubview:startButton]; [startButton setFrame:CGRectMake(margin + 25, answerButtonBoxTop + 5, answerButtonBoxWidth - 50, buttonHeight)]; startButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; [startButton addTarget:self action:@selector(startQuiz) forControlEvents:UIControlEventTouchUpInside]; [startButton.titleLabel setFont:[UIFont fontWithName:@"Chalkduster" size:questionFontSize+3]]; [startButton setTitle:NSLocalizedString(@"quizStart",@"Start Quiz") forState:UIControlStateNormal]; [startButton.titleLabel setTextColor:[UIColor blackColor]];
 
MGoBlue
Apple Fan
Profile
Posts: 980
Reg: Jun 07, 2011
Gold River, CA
10,600
like
09/04/12 06:19 AM (13 years ago)
Sorry. Didn't copy all the code: //create rounded rectangle start button startButton = [UIButton buttonWithType:UIButtonTypeCustom]; //sets the type of UIButton UIImage *buttonBackgroundImage = [UIImage imageNamed:@"menubkgrnd.png"]; //startButton is declared as an instance variable UIButton in the interface [startButton setBackgroundImage:buttonBackgroundImage forState:UIControlStateNormal]; [super viewDidLoad]; [self.view addSubview:startButton]; [startButton setFrame:CGRectMake(margin + 25, answerButtonBoxTop + 5, answerButtonBoxWidth - 50, buttonHeight)]; startButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; [startButton addTarget:self action:@selector(startQuiz) forControlEvents:UIControlEventTouchUpInside]; [startButton.titleLabel setFont:[UIFont fontWithName:@"Chalkduster" size:questionFontSize+3]]; [startButton setTitle:NSLocalizedString(@"quizStart",@"Start Quiz") forState:UIControlStateNormal]; [startButton.titleLabel setTextColor:[UIColor blackColor]];
 
jorge10
Aspiring developer
Profile
Posts: 36
Reg: Aug 24, 2012
Barcelone
2,060
like
09/04/12 08:50 AM (13 years ago)
Hi MGoBlue: Thank you very much. I see the letter inside " " over the menubkgrnd.png but no problem. I will create a blank background image. I really appreciate your help. Thank you!!! Jorge
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
09/04/12 08:55 AM (13 years ago)
Thanks. I tinkered with this but failed. Now I understand why. Appreciate the code samples! (and sorry @ that game Sat. Not sure Toussaint makes much of a difference. Way to suck the wind out of your teams sails before a huge game Hoke!) 18 days and I *might* have a line on a ticket in South Bend! The 7:30 start however, I might not be able to stand after a 10hr tailgate!
 
MGoBlue
Apple Fan
Profile
Posts: 980
Reg: Jun 07, 2011
Gold River, CA
10,600
like
09/04/12 10:27 AM (13 years ago)
@ATRAIN53 - Seriously. That was painful to watch. I never understand why Al Borgeous doesn't let Denard loose in the early part of the season. Same thing last year. The first four or five games it seemed like everything was designed for a pocket passer, not someone with Denard's explosive potential. Looking forward to the battle with the Irish. Always a good rivalry. When I was in school, nearly every game came down to a field goal with time running out.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.