0

I am trying to create a shopping cart application , Now on adding any product i want to add badge on a UIButton which will increase or decrease accordingly .

I searched google but end up with the solution " MKNumberBadgeView " (https://www.cocoacontrols.com/controls/mknumberbadgeview)

I am creating application that supports iPhone4/5 so i am afraid to add a sub view in my view controller and manage on iPhone 4 & 5.

can any one suggest a better solution so that i can get a badge on UIButton along which also supports orientation . or a Solution to Handle subview for Both devices 4 & 5.

Thanks in advance .

vinay chorpa
  • 187
  • 3
  • 16

1 Answers1

0

Managing whether it is an iPhone 4 or 5 is not a ton of work, it really only makes a difference when you initialize the button and that is it.

You can do this by getting the screen size using the following code

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.height == 568) {
    // This is an iPhone 5
} else if (screenBounds.height == 480) {
    // This is an iPhone 4S or below
} else {
    // Some other device, maybe an iPad?
}

Then just add the button in that way, pretty straightforward

MZimmerman6
  • 8,445
  • 10
  • 40
  • 70
  • Agreed with your point .. but if the screen rotates then how to manage the rotation of the button .. any snippet of code will be a real help :) – vinay chorpa Aug 13 '13 at 13:24
  • This should be handled already. If not, just use the callback method for when the screen rotates, and then rotate the button if necessary. – MZimmerman6 Aug 13 '13 at 13:26
  • one last thing can you suggest that if i create a rect for a UIButton and add it on the view , then what is it a good idea to hardcode the location of a button with its co ordinates or it can be managed with some other technique. – vinay chorpa Aug 13 '13 at 13:34
  • generally if you are adding a view or button, through code, you will have to hard-code in the coordinates. These of course can be updated at any time by updating the `frame` property, or by adding a translation/rotation transform to the `transform` property. Just create the view using `[... initWithFrame:CGRectMake(originX,originY,width,height)]` it is pretty easy – MZimmerman6 Aug 13 '13 at 15:09