I have the following code to show a simple button:
button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
button.center = CGPointZero
button.frame = [[container.width/2-button.frame.size.width/2,150], [280,50]]
button.setTitle("Categorize New Project", forState: UIControlStateNormal)
button.addTarget(self,
action: "moveToChildView:",
forControlEvents: UIControlEventTouchUpInside)
When I run this app in simulator iPhone retina (3.5 inch) with 6.1 it looks like this:
However, when I run it in simulator iPhone retina with 7.0 it looks like this:
Does this code need to change to work well with 7.0?
As of iOS 7 the default rounded rectangle button looks like this. See the UI transition guide. I suggest using custom buttons to prevent such discrepancies between versions.
As Alexander said it is new look of iOS7 and he also suggest to use custom buttons, which is good advice,
But here there is one another way to solve this problem which will give you bellow output
Using this code
self.myButton.layer.cornerRadius = 10;
self.myButton.backgroundColor = [UIColor whiteColor];
self.myButton.layer.borderWidth = 1.0f;
Related
I would like to use a Custom header instead of default UINavigationBar. I am able to do it well, until I encountered a condition to keep the backward compatibility with iOS6 too. I have my previous question here ,un-answered.
Recently for Facebook App, I can see in iOS7, the blue-color header bar well aligned. To me it looks like its a custom header, I am not sure. FaceBook-Header
Now the problem is that, I am stuck with implementation of my custom app header. My Custom header height is 48px which goes behind the "network status bar" on top & I am getting only approx 35pixel as the rest is behind the "network status bar" like this.
Here are my goals to achieve.
I want a custom header. - Done
I don't want to use UINavigationBar. - Done
I want the support for iOS 5.0 till 7.0 - Stuck
Here is what it looks when I am using Custom header
Here is what it looks with UINavigationBar
How I can make app headers to appear like "FaceBook header" with "Custom Header" without getting underneath the "top network Header bar". If I Increase the height of Status Bar, it will look odd in iOS6 & older, but fits well in iOS7. I want to choose the right approach.
Any expert help is highly appreciated.
You need to place UIToolbar in xib,
and add background image in toolbar,
self.navigationController.navigationBarHidden = YES;
[self.toolBar setBackgroundImage:[UIImage imageNamed:#"background.png"] forToolbarPosition:UIToolbarPositionAny barMetrics: UIBarMetricsDefault];
add bar button,
UIButton *facebookButton = [UIButton buttonWithType:UIButtonTypeCustom];
[facebookButton setImage:[UIImage imageNamed:#"facbookBarImage.png"] forState:UIControlStateNormal];
[facebookButton addTarget:self action:#selector(action:)forControlEvents:UIControlEventTouchUpInside];
[facebookButton setFrame:CGRectMake(0, 0, 53, 31)];
UIBarButtonItem *facebookBarButton = [[UIBarButtonItem alloc] initWithCustomView: facebookButton];
self.toolBar.items = [NSArray arrayWithObjects: facebookBarButton,nil];
After some Research on Compatibility, I have come across a working solution to make a Custom header with no UINavigationBar & achieving what I was looking for. Feel free to use this approach.
Here are my results : iOS7 and Older iOS.
The approach is to figure out edgesForExtendedLayout (available in iOS 7). If we are on iOS7 then decide the height of "Custom Header" (probably 10Pixel more than what we keep in older version, so as to pad the extra 10Pixel underneath the "Top Network status bar").
Figure out the iOS7 compatibility for edgesForExtendedLayout here
CGFloat y;
if ([self respondsToSelector:#selector(edgesForExtendedLayout)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
y= 58;
}else {
y = 48;
}
Make Custom header with height of y here
self.customHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, appDimensions.width, y)];
Custom buttons on customHeaderView here
self.sideMenuButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.sideMenuButton setFrame:CGRectMake(0, y-45, 45, 45)];
So Now if I run this on iOS7, I see my header with enough height of 48pixel (more than what we have in Human Interface Guidelines for Touch Area (44 x 44)) even being 10 pixel is underneath the "Top network status bar).
If I run this in iOS < iOS7, I will have my custom header of 48 Pixel, starting right beneath the "Top network status bar"
Hope this helps other.
Hello guys I am trying to add localization in my app and I am using storyboards. I added "Base Internationalization" and it does not appear to be working... For example in my Locilizible.strings(French) I have:
and in my storyboard I have:
however when I run in the French Simulator I get:
Anyone know why?
Try this....
[button setTitle: NSLocalizedString(#"Set Subject:", nil) forState: UIControlStateNormal];
This link may help: Storyboard/XIB and localization best practice
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"
just switched to iOS 4 on my iPhone 3GS and some of my apps broke.
One issue I had is that I had a UIToolbar with some buttons, tinted to pink, that worked well on the 3.1.3 OS. After upgrading to iOS 4, the toolbar was still tinted, but the buttons it contained were no longer affected by the tint. The toolbar was pink while the buttons were regular-blue.
Looked around for it on the net, but found no reference of such a thing.
Anyone knows what broke in the process?
(must be frank here - I knew the answer before posting, just didn't know how to load this data to StackOverflow. Thought the solution I found was valuable for others, so wanted to post it here. I'm new here, so please no harsh critics :) )
So eventually the problem resulted from, AFAICT, a change in behavior in the OS.
As stated the tint code worked before the upgrade and was written like this:
// Toolbar content
NSArray *items=[NSArray arrayWithObjects: ... ]; // PSEUDO CODE HERE
[toolbar setItems:items];
// Add tint
toolbar.tintColor = [UIColor colorWithRed:0.83 green:0.43 blue:0.57 alpha:0.5];
What I needed to do, was just reverse the order of things:
// Add tint
toolbar.tintColor = [UIColor colorWithRed:0.83 green:0.43 blue:0.57 alpha:0.5];
// Toolbar content
NSArray *items=[NSArray arrayWithObjects: ... ]; // PSEUDO CODE HERE
[toolbar setItems:items];
(If you created UIToolbar in Interface Builder, you can change it's tint there, and that applies for the buttons as well).
I guess the tint updated all buttons before iOS 4, while in iOS 4 it doesn't and when adding buttons, they check for existing tint. But this is just a guess. The solution works anyhow..
Hope this helps someone, and that I didn't violate any sacred SO rules...
Cheers!
Well, it seems more like an OS bug than a feature, since navigation bars do change their item's color when you set their tintColor.
We've found that if you change the item's style, it refreshes their color as a side effect. Doing the following worked in our case. The original buttons are bordered, so we change them to plain and set them to bordered again. You may do a more complicated and generic code that saves the current style, sets another one and then switchs back. I am just to lazy to do that. :D Anyway, you get the idea.
toolbar.tintColor = //<some dynamically obtained UIColor>
// Workaround to properly set the UIBarButtonItem's tint color in iOS 4
for (UIBarButtonItem * item in toolbar.items)
{
item.style = UIBarButtonItemStylePlain;
item.style = UIBarButtonItemStyleBordered;
}
Regards,
Rula.
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.