How to place UIStepper vertically? - ios

I am developing a products storage app and need to implement a UIStepper in it. The problem is that I just can't place it vertically as I would like to have it.
So does anyone know a way I can do this??

You should be able to modify the transform:
stepper.transform = CGAffineTransformMakeRotation(M_PI / 2.0);
Edit:
I now see that this is problematic for IB. I often create my views programmatically and this does not seem to be an issue:
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(150, 150, 27, 94)];
// this doesn't even have a problem:
UIStepper *stepper = [[UIStepper alloc] init];
It only seems to be an issue with IB. Setting the frame after the fact also does not seem to help.

Related

Text of textview is overlapping under textview

My question is simple and I think it is possible but I cant find it.
My design is like this
I give corner radius to textview and also set textContainerInset for padding from right and left both side
txtview_msg.textContainerInset = UIEdgeInsetsMake(5, 10, 10, 5)
Now my problem is like for first 2 line and last 2 line my text goes beneath textview so I need some solution for it.
Please help me into this. Thank you
try this code
UIView *paddingView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, txtview_msg.frame.size.height - 30)];
txtview_msg.leftView = paddingView1;
txtview_msg.leftViewMode = UITextFieldViewModeAlways;
UIView *paddingView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, txtview_msg.frame.size.height - 30)];
txtview_msg.leftView = paddingView2;
txtview_msg.rightViewMode = UITextFieldViewModeAlways;
You can create at first a view of same size how much you given, put cornerRadius how much you given in textview now. than create textview viewSize - corner radius. place the textview exactly in middle of view. set the constraints from that view only, than it will work perfect how you want.
check this attached screenshot:

UITextField RightView crash app when using 2 or more

I don't know if this is a bug or what but I can't understand why it happens.
I have 2 UITextField that once clicked show the users an UIPickerView, everything was working fine until I tried to add a custom arrow image in order to let the user know about the dropdown. this is the code I've used in order to create the rightView:
UIImageView *arrowDown = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"p-dropdown"]];
arrowDown.frame = CGRectMake(0, 0, 26, 22);
_province.rightViewMode = UITextFieldViewModeAlways;
_province.rightView = arrowDown;
_address.rightViewMode = UITextFieldViewModeAlways;
_address.rightView = arrowDown;
As soon as the last line ends the app freezes and it starts using like 20MB/s of RAM without stopping, I tried to comment all the code above and the problem doesn't occur, the funny thing is that if I comment just one of the two rightView ,so something like this:
UIImageView *arrowDown = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"p-dropdown"]];
arrowDown.frame = CGRectMake(0, 0, 26, 22);
_province.rightViewMode = UITextFieldViewModeAlways;
_province.rightView = arrowDown;
I can correctly see the rightView and the app doesn't freeze. Can someone help me to understand what is causing this weird issue?
One instance of UIView can't be utilized as right view of multiple UITextFields. You have to make two instances of your UIImageView to make your app work as expected. As you yourself found out, that one view cant be displayed on a screen multiple times simultaneously.

Custom navbar sizing from iphone 5 to iphone 6

I have a custom tab bar that was optimized for the iphone 5.
UINavigationBar *myBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:myBar];
When it on the iphone 6, part of it is cut off of course because it only goes to 320 pixels.
How do i fix this? Is there a way to check which iphone its being ran on, and then run the pixel specified code? I plan on putting a background image on this navbar later so it must be centered.
In general it is a bad idea to hard code dimensions like this. This will break if you rotate, or if viewed on a screen with a different size than the original iPhone screen.
Many of these controls have a default size that you can use to your advantage. Instead of handing it a frame, consider just modifying the frame it gives you:
UINavigationBar *myBar = [[UINavigationBar alloc] init];
CGRect navBarFrame = myBar.frame;
navBarFrame.size.height // returns the right size for the current OS
navBarFrame.size.width = self.view.frame.size.width;
myBar.frame = navBarFrame;
This type of defensive coding is helpful in keeping your app laid out properly under many conditions, including when you embed this control into a parent view controller, or viewed on tomorrows larger-screened iOS devices.
All this said, are you sure you don't want a UIToolbar? Typically you don't ever create your own UINavigationBar, as that class is just used in UINavigationController for you.
UINavigationBar *myBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 50)];
[self.view addSubview:myBar];
may be this help you.

Coded UIStepper not displaying

After not finding an answer I have to again ask you all for help. I am creating a UIStepper programatically but it will not display. Labels, buttons, and switches are all displaying properly so I must be missing something related to the stepper.
Elsewhere in my code I declare and initialize UIView *v and NSMutableArray *steppers, and declare UIStepper *st. The code to create the stepper is:
st = [[UIStepper alloc] init];
st.frame = CGRectMake(xnear, ypos, 0, 0);
[st addTarget:self action:#selector(stepper1:) forControlEvents:UIControlEventValueChanged];
[st setMinimumValue:0];
[st setMaximumValue:99];
[st setWraps:NO];
[st setContinuous:NO];
[v addSubview:st];
[steppers addObject:st];
At runtime xnear = 100 and ypos = 250, so the stepper is within the display. A label immediately above, and a text field immediately below, are displaying. Other questions regarding the UIStepper state the width and height are ignored, so I used 0 for both. Is there anything obviously wrong with this code?
You are setting height and width of UIStepper as 0
st.frame = CGRectMake(xnear, ypos, 0, 0);
give some height and width
st.frame = CGRectMake(xnear, ypos,200, 100);
The answer is, quite frankly, embarrassing. A custom background color was set for the UIView and no color was set for the control. I was able to get the stepper to show up with the following line of code:
st.backgroundColor = [UIColor whiteColor];
Similarly, the UISegmentedControl *sc showed up when I added:
sc.backgroundColor = [UIColor whiteColor];
Thanks for the help and sorry to waste your time!

Custom UITable in FBFriendPickerViewController

I would like to know if there is any way to completely replace FBFriendPickerViewController's UITableView or modify the current one.
I need to reverse colors on the table ( white labels, black background) and I wasn't able to do that. So far, I was able to replace table's background but nothing else worked.
I tried something like:
self.myFriendPicker = [[FBFriendPickerViewController alloc] init];
self.myFriendPicker.delegate = self;
[self.myFriendPicker loadData];
[self.myFriendPicker clearSelection];
self.myFriendPicker.allowsMultipleSelection = NO;
self.myFriendPicker.view.frame = CGRectMake(30, 50, 250, 340);
And then I tried to create a new UITableView with red background to try it out and see if it works.
UITableView *tbView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 100, 100) style:UITableViewStylePlain];
tbView.backgroundColor = [UIColor redColor];
self.myFriendPicker.tableView = tbView;
It didn't work and I would appreciate some suggestions.
Thanks for help.
I ended up implementing my own fabecookfriendpicker as a subview of uitableview.Displayinging the list of your friends is not a big issue but even though It is not a straightforward task since you need to lazy load the images and so on.
You have more opportunities to custumize the view with approach.But you can also try subclassing the FBFriendPickerViewController itself

Resources