Custom UISlider behaving different on iOS 4.3 and iOS 5 - ios5

I have some sliders in my app that are customized using setMinimumTrackImage:forState: and setMaximumTrackImage:forState:
On iOS 4.3 devices they show up exactly how I want them to look, but when running on iOS 5 devices the textures are being stretched incorrectly.
Is this a known issue? Did something about UISliders change in the iOS 5 update?
Thanks

I had similar problem before where the track images always show up okay in iOS 4 but not in iOS 5. I tried to make the images resizable. And it worked for me. Please try this:
UIImage *leftTrackImage = [[UIImage imageNamed:#"progress_left.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *rightTrackImage = [[UIImage imageNamed:#"progress_right.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];

did you try to use stretchableImageWithLeftCat:TopCap: ?

Related

WKInterfaceImage and dynamic images on watchOS 2

If I create a UIImage and display it using a WKInterfaceImage it always displays the image as #1x instead of #2x resulting in a pixelated image. It worked fine with watchOS 1. How to fix this behavior with watchOS 2? The same code works fine on iOS with a UIImageView.
Here is the solution for creating the image from an NSData object on the Apple Watch at the correct screen scale.
UIImage *image = [UIImage imageWithData:imageData scale:[[WKInterfaceDevice currentDevice] screenScale]];

how to create iphone application which is compatible for iphone 4 and 5 screen sizes [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to develop or migrate apps for iPhone 5 screen resolution?
I have two sets of images.One set of images to iphone 4 background images and other set of images to iphone 5.How can I use these two image sets to create my iphone application which wants to be compatible with both screen sizes ?
do I want to check the iphone version and apply images using some coding ?
Hope you can help.Thanks for the help.
I am using a class extension called UIDevice. You can find the source here: https://github.com/erica/uidevice-extension
I have set up a neat little method which layouts the view according to screen size.
Example:
- (void)setupGUI
{
UIImage *backgroundImage;
if ([[UIDevice currentDevice] platformType] == UIDevice5iPhone)
{
//4 inch screen
backgroundImage = [[UIImage alloc] initWithCGImage:[UIImage imageNamed:#"main_background-568h#2x"].CGImage scale:2.0 orientation:UIImageOrientationUp];
}
else
{
//3.5 inch screen
backgroundImage = [[UIImage imageNamed:#"main_background"] retain];
}
self.view.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];
[backgroundImage release];
}
For the splash you can use the suffix -568h#2x
For UIImage you can use:
[UIImage imageNamed:#"tryImage"]
And you can have tryImage.png, tryImage#2x.png and tryImage-568h#2x.png, but it seems not to be working as we would like.
You can also use a trick like this: https://gist.github.com/3782351

Button with background image - iPhone 5 resize issue

I have been looking everywhere on here and Google, but I still have this weird issue that I can't figure. I have an app pictures below, with 4 UIButtons that have a background image applied:
When I resize/run on the iPhone 5, the top button resizes in a very strange way:
How do I get all the UIButtons to resize the same way with the iPhone 5? Is it possible? Do I need to use a different method?
I really hope this is not a duplicate, but I am completely stumped. If I change the UIButtons around in other positions along the UIView, a different one will resize, or strange gap spacing will show up.... I don't understand. Thanks for any help!
EDIT: I am using iOS 6 on Xcode 4.5. I am testing on an iPhone 4S and an iPhone 5. I have AutoLayout checked. If I use Pin (just found it) I can get the UIButton to keep its height.
To clarify my question. I want the UIButtons to resize so they occupy the same percentage of the screen.... I want the proportions to be the same, instead of simply adding a bunch of empty space. I hope that make it more clear
One of the features you can use is called AutoLayout. Its provided with Xcode to make it easier adjusting things for the 4 inch screen. You can find a good example here: http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
But as far as I know AutoLayout works only with iOS 6 which makes it "not so useful yet". I have been using a class called UIDevice, source of which can be found here: https://github.com/erica/uidevice-extension and check if the platform type is iPhone 5. I have it set up in a method which setups GUI when the view loads. Example of my implementation:
UIImage *backgroundImage;
if ([[UIDevice currentDevice] platformType] == UIDevice5iPhone)
{
//I have a 4 inch screen present
myButton.frame = CGRectMake(x, y, w, h); //Set the frame as you would like it to look on the iPhone 5
backgroundImage = [[UIImage alloc] initWithCGImage:[UIImage imageNamed:#"main_background-568h#2x"].CGImage scale:2.0 orientation:UIImageOrientationUp];
}
else
{
//I have a 3.5 inch screen present
myButton.frame = CGRectMake(x, y, w, h); //Set the frame as you would like it to look on the iPhone 3, 3gs, 4, 4s...
backgroundImage = [[UIImage imageNamed:#"main_background"] retain];
}
self.view.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];
[backgroundImage release];
Hope it clears a bit.
you should firstly disable the use AutoLayout this option is under the "Show the file inspector"

What should I do to adapt my app to iOS 5.0 keeping compatibility with iOS 4

I've started playing with iOS 5 today and I've seen that XCode 4.2 only let me select iOS 5 as Base SDK but not iOS 4.
Until now I've overwriting drawRect: method in UINavigationBar to customize its appearance but iOS 5 doesn't call that method anymore. Now I've to use [UINavigationBar appearance] to do it (which I think is much better). However, appearance method is only available in iOS 5 so if I use it my app it crashes when executing on iOS 4. What should I do? Do I have to check iOS version with macros in every place I use a iOS 5 method?
Thank you,
Ariel
The answer to your first question is: You must use iOS5 (or Latest iOS SDK) as your base SDK, but you set your minimum supported iOS version under Deployment Target. There you can set iOS4.0 (or whatever you want).
The correct way to deal with your second question is to test for capability, not version. So, something like this would work in say, your application:didFinishLaunchingWithOptions: method:
// iOS5-only to customize the nav bar appearance
if ([[UINavigationBar class] respondsToSelector:#selector(appearance)]) {
UIImage *img = [UIImage imageNamed: #"NavBarBackground.png"];
[[UINavigationBar appearance] setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
}
You will then be compiling this against the iOS5 SDK, so the use of appearance at all will be fine. But when this compiled code runs on a version of iOS before 5, it will be fine.
As said before, you can keep your drawRect: code as-is.
Another way to customized your header is like this.
UIImage *image = [UIImage imageNamed:#"header.png"];
if([navigationBar respondsToSelector:#selector(setBackgroundImage:forBarMetrics:)] ) {
//iOS 5 new UINavigationBar custom background
[navigationBar setBackgroundImage:image forBarMetrics: UIBarMetricsDefault];
}
else{
UIImageView *imgView = [[[UIImageView alloc] initWithImage:image] autorelease];
[imgView setUserInteractionEnabled:NO];
[imgView setTag:TOOLBAR_TAG];
[navigationBar insertSubview:imgView atIndex:0];
}
Using the respondsToSelector you can know if the function is here.
You can put the same piece of code in both the drawRect: that iOS 4 uses and the proxy returned by [UINavigationbar appearance]. Two different code paths.
You can't do this with macros since both code paths have to be in place and the correct route to go depends on a run-time check.
Soooo... use something like this:
NSString *os_version = [[UIDevice currentDevice] systemVersion];
to get the iOS version you're currently running on and do the [UINavigationBar appearance] under 5 & newer, and you can fall back to the drawRect thing on iOS 4.
Also take advantage of downloading the 4.3 simulators for iPhone and iPad. Then you can crash faster when you accidentally use iOS 5 stuff on 4.3
--Tom

iPhone: image in table cell - wrong position & not scaled correctly in iPhone 3.0

I have a custom table cell in an iPhone 3.x app to show basketball player data, including a picture. Here's my code from the table controller:
UIImageView *theImage = (UIImageView *) [cell viewWithTag:0];
theImage.image = [manager getSmallImageForPlayer: data.number];
theImage.frame = CGRectMake(14, 0, 30, 44);
theImage.clipsToBounds = YES;
theImage.contentMode = UIViewContentModeScaleAspectFit;
theImage.autoresizingMask = UIViewAutoresizingFlexibleHeight && UIViewAutoresizingFlexibleWidth;
theImage.autoresizesSubviews = YES;
Here's what it looks like in the iPhone SDK 3.0 simulator:
3.0 simulator screenshot http://img96.imageshack.us/img96/9550/imageintablecell30.png
Here's what it looks like in the iPhone SDK 3.1.3 simulator:
3.1.3 simulator screenshot http://img185.imageshack.us/img185/9269/imageintablecell313.png
So I have two problems:
In both versions, the image view starts at position (0,0) in the table cell, even though I set the frame to start at (14,0).
In the 3.0 simulator (and 3.0 device), the image is not shrunk down correctly, even though I set the image view content mode to "UIViewContentModeScaleAspectFit". But the same code works fine in the 3.1.3 simulator / device.
Who can help me with either of these two problems?
You could try creating your own UIImageView and adding it as a subview to table cell
I found the answer on the Apple forums: Using "0" as the tag number for the image view screwed things up; just changing it to "5" made both problems (image not scaled, wrong position) go away.