Base Internationalization not working - iphone

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

Related

Button behaving differently in 6.1 vs. 7.0

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;

Modifying MWPhotoBrowser in iPhone

Hi I am have added the MWPhotoBrowser in my iPhone application it works great but now i need to add a little more functionality to my photo gallery.
basically what to do a couple things:
add a button to the navigation bar
decrease the space between two images.
However I don't know how to approach this problem.. should I subclass the Photo Browser or should I make changes in the Photo Browser's source code.
P.S. i tried to modify the code directly in MWPhotoBrowser.h file which didn't work. No changes were made. I'm super new to iPhone programming so i don't have much idea what is going on. Any help would be greatly appreciated. I know its a noobish question so please go easy on down votes :)
In the MWPhotoBrowser.m file find the setNavBarAppearance method and add this
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self action:#selector(someAction)]; // This can be changed to your liking
self.navigationItem.rightBarButtonItem = rightButton;
[rightButton release];
Set the Padding : 10 to 0;
Its done.
Thnaks

UIButton setImage not working

I'm losing my mind over this one. I have UIButton connected as Outlet. I want to change it's image. In the viewDidLoad function, I try to set the image like so:
[button1 setImage:[UIImage imageNamed:#"house.png"] forState:UIControlStateNormal];
Nothing happens. However, if I use ImagePicker, it somehow works. In the ImagePickers function "didFinishPickingImage", I repeat the exactly same command as above for setting image and it works, the image is displayed normally.
I've been thinking that maybe the button's image is not refreshing itself, but trying to call [button1 setNeedsDisplay], or [button1.imageView setNeedsDisplay] or even [button1.imageView.image setNeedsDisplay] does nothing.
Does anyone have any idea about this? I've wasted two hours by now and I'm really getting frustrated, because I'm certain that the reason must be so stupid it's unbelivable.
Please check your button type.
If your button type is "System" you should change it to "Custom"
Two things to do here:
#1, change your code to:
[button1 setImage:[UIImage imageNamed:#"house.png"] forState:UIControlStateNormal];
and #2
make sure your UIImage returns a valid image.
In other words,
UIImage * imageToSet = [UIImage imageNamed: #"house.png"];
if(imageToSet)
{
[button1 setImage:[UIImage imageNamed:#"house.png"] forState:UIControlStateNormal];
} else {
// if you see this line in your console, then you know where to look for a problem
NSLog( #"why is my image object nil?");
}
For anyone who will find themselves in a similar situation; I was using the mentioned button inside a custom cell for table view. However, the cells aren't loaded right away (i.e. inside viewDidLoad/viewWillAppear etc.), but inside the tableView:cellForRowAtIndexPath function. All my button variables were nil at that point. My solution was to load the image after the cell has been created and it has worked straight away afterwards.
Here are a couple additional notes. UIButton setImage: forState: is the correct method:
[button1 setImage:[UIImage imageNamed:#"house.png"] forState:UIControlStateNormal];
imageNamed is a great convenience method for grabbing the image, but make sure it returns an object. Forgetting to include the image file in the current target gets me all of the time.
[UIImage imageNamed:#"house.png"]
You also don't need the extension. The SDK works this out.
[UIImage imageNamed:#"house"]
And even though UIControlState is a bit mask, you cannot OR the values together. This does not not not work and I must must must remember this because it gets me every time I use the call.
// NO NO NO
[button1 setImage:[UIImage imageNamed:#"house"] forState:UIControlStateNormal|UIControlStateSelected];
// YES
[button1 setImage:[UIImage imageNamed:#"house"] forState:UIControlStateNormal];
[button1 setImage:[UIImage imageNamed:#"house"] forState:UIControlStateSelected];
Was getting the same problem when UIbutton was in UITableViewCell.
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:#"detail.png"] forState:UIControlStateNormal];
should work in UITableViewCell
Glad to know that the problem is solved but none of the answers actually addresses the problem.
Generally, if the code is correct, then the error shifts from "syntax error" to the "logical error" category. There is no definite guide to handle it but here is a small checklist that can help anyone to troubleshoot their code.
1) The IBOutlet is not connected or renamed.
2) Make sure that the UIButton type is custom.
3) The image is set (more than once), somewhere else in the code.
4) You are trying to set the Image through any sync method which is not using the main thread. (There are several threads on that alone).
5) If you are nesting the images as subviews, make sure the problem isn't with their parent view.
6) If it is appearing in Simulator but not in the device, It's a lettercase (Uppercase, lowercase difference in the code and the filename.
7) Modern simulators works with very low GPU memory on older machines. You can tweak the simlator options to make it appear. E.g (Command + Right Arrow) twice to change the simulator orientation and your changes will appear.
There are few other but common pitfalls where developers usually overlook
1) The image doesn't exist OR you are making a spelling mistake.
2) The filetype is different than mentioned. (JPG, PNG).
Last thing you'll want to check - make sure you're setting the image on the main thread! Just ran into an issue where I was setting a button image in a callback from ALAssetLibrary (fetching images from photo library). The image wouldn't update until I tapped the button. Turns out the callback was happening off main...
for those having issues with system images not appearing, just use systemName: instead of named
if let starImg = UIImage(systemName: "star.fill") {
button.setImage(starImg, for: .normal)
}
It's for ios13 and later...
For me it was to move the line:
[button1 setImage:[UIImage imageNamed:#"house.png"] forState:UIControlStateNormal];
from awakeFromNib method
to viewDidLoad method
I guess,
don't create like this
UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
by this create method ,UIButton is create by use default type,so your background image is not work.
try this,
UIButton *nextButton = [[UIButton alloc] initWithFrame:CGRectMake(9, 154, 300, 48)];
or other,except buttonWithType
This is happening because the state of the Button doesn't stays selected once clicked by default.
I solved it by making an IBaction on that button click and toggling the selected state.
-(IBAction) checkButtonClicked:(id)sender{
checkButton.selected = !checkButton.selected;
}
In my case, it is drawn by custom animation code and not set by the image, so it doesn't work by setting any image, it has to change the animation code.
With images, you have to import them into the project not as references but as copies. So when you go to add files to project, choose "Create groups" instead of "Create folder references". Also make sure "Copy items if needed" is checked.
This is confusing because importing as references works when you are using images as textures (e.g. for Sprites). However, it doesn't work when you want to use images for buttons (e.g. for using image name in [UIImage imageNamed:#"house.png"]
I faced this same issue of the image not being shown on the UIButton.
I had to change this line -
myButton.setImage(<my_UIImage_object>, for: [.normal, .focused])
to this -
myButton.setImage(<my_UIImage_object>, for: .normal)

iPhone + UIControls

It is a very generic question (not related to any application). Just my quest to know more.
While creating any iPhone application, we see that there few UIControls available in Library of Interface Builder. Using those we can create all basic application and designs, and also we can't customize those to much extent
But if we see on App Store, thousands of applications are available, where there many UIControls which are either not available in Library or might be they customized to much extent.
I want to know that:
Can we use controls other than available in Library (if yes than how and from where to get that).
If we can't than how do we modify (customize) the available UIControls to such an extent that they look totally different from their original primary look.
Regards,
Pratik
For a start, it is possible to set an image (including transparency) for most controllers. Many controller that look like different controls may actually be the same controls, just reskinned. Many controllers allow subviews - it is amazing how much can be achieved just using the table controller.
It is also worth knowing that any control you place using the GUI can also be set to a subclass where you override behaviour. Simply select the control, hit Shift-Apple i and change the class in Class Identity.
For customised controllers you can check the Three20 Project by Joe Hewitt.
take a look at the three20 library. It include custom styled button, labels and text. It should give you the general idea, how to customize your own UI elements.
Often, you don't use images like casebash mentioned, instead your drawing your elements with graphical methods.
Another possible solution is to override your
- (void)drawRect:(CGRect)rect
of your UIView
Edit:
Source Code taken from
Custom UIButton for Iphone
INDEX_OFFSET = 82753; // random
UIButton *sampleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[sampleButton setFrame:CGRectMake(kLeftMargin, 10, self.view.bounds.size.width - kLeftMargin - kRightMargin, 52)];
[sampleButton setTitle:#"Button Title" forState:UIControlStateNormal];
[sampleButton setFont:[UIFont boldSystemFontOfSize:20]];
[sampleButton setTag:<INDEX>+INDEX_OFFSET];
[sampleButton setBackgroundImage:[[UIImage imageNamed:#"redButton.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
[sampleButton addTarget:self action:#selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:sampleButton];

Change the color of a Tabbar on the iPhone

Our designers want to change the color of the default UITabBar. Of course they do.
They want the background to be green, and the icon highlights to be white, as opposed to the black/blue default color scheme.
Anyone have any experience or suggestions to do this?
You have to subclass the UITabBarController and implement custom drawing.
Check out this SO question. Changing Tint / Background color of UITabBar
Since iOS5 is released, you can now use the property tintColor.
i.e.:
tabBar.tintColor = [UIColor greenColor];
I have try this one and its working for me!!!
[self.TabBarController.tabBar setTintColor:[UIColor colorWithRed:0.1294 green:0.5686 blue:0.8353 alpha:1.0]];
[self.TabBarController.tabBar setTintColor:[UIColor "YOUR COLOR"];
Hope it'll help you also!!!
iOS 5.0 fixes this issue but the solution is under NDA. Look up UITabBar in your documentation for an EASY way to do what you want to do.
Be careful. If your app is going for submission to the app store, Apple may reject it if you're modifying their prescribed color scheme.
Theres a useful link here: http://duivesteyn.net/2010/01/16/iphone-custom-tabbar-background-image/
This can be done with a little private API hacking.