UIPickerView Separator lines - ios

I am using Xcode 7.1.1 in my application I am using UIPickerView for selecting countries. It's working fine, I need two separator lines.
I tried to use this code:
[myPicker.subviews objectAtIndex:1].backgroundColor = [UIColor redColor];
[myPicker.subviews objectAtIndex:2].backgroundColor = [UIColor redColor];
but it showing line only in the bottom, in the top there is no line. Is there any way to show two lines between the bold text?

the myPicker.subviews you are trying to access is not something you know about. It does not contain what you think, that is, view or anything. Its apple private api and it can be anything. You cannot depend on it. It also depends on OS.
To make the selected text some sort of distinctly visible what you alternatively do is for all model objects create a corresponding UILabel in a loop and then use them to supply the data to the picker. Then in the
pickerView:didSelectRow:inComponent:
set some distinct property of your UILabel like change its textcolor or font.

add 1 pixel view in xib
hide both view & picker.
when you show picker..then display picker & 1 pixel view
when you click on cancel or Done remove your picker & 1 pixel view

Related

UIsegmentedControl title appearance

HI, i set my uisegmentedcontrol's width manually, but when the width gets too small, the words becomes ...
Is that anyway that it won't behave in this way? Instead, i just want to show the text just like the picture shown below.
I'd suggest changing your design here and going for a different approach.
The design that you seem to want makes readability pretty much impossible.
Plus, what happens if I'm using your app and add another "Active Project". What happens if I have 10 active projects?
Take the fact that the UI does not work as a sign that you are using the wrong UI for the problem you are trying solve.
I'd suggest possibly just have the current project title here with a button to maybe present a list of projects to switch to... or something.
The text has been truncated. If you want it to fit your segment, you need to update the segment control size based on the text length. If you just want to get rid of truncation, you can use the following snippet. However, it's not recommended, as later Apple might change the UISegmentControl hierarchy.
for item in segmentedControl.subviews {
for subview in item.subviews {
if subview.isKind(of: UILabel.self) {
let _label = subview as! UILabel
_label.numberOfLines = 0
_label.lineBreakMode = .byWordWrapping
}
}
}

how to create day/night mode for my app

I am looking to create a toggle in my application
Day | Night
Day is considered the default setting. When the user selects the Night mode i want all the color of all the UI elements to be inverted.
Here are the kind of elements i mean:
UILabels
Buttons
Tabs
Pickers
Window Backgrounds
Everything else that is a UI object
I have tried using the following:
[[UIApplication sharedApplication] keyWindow].tintColor = [UIColor redColor];
This has the following issues:
This does change the color of many elements of the app but not
all. Like for instance it does not change the color of the UILabels
It does not invert the color. It simply changes the color for all
the object to a particular value.
Does not change the background color of the window.
Is this even possible with a quick bit of code?
You need use the UIAppearance for customize your labels, buttons, etc.
You can see this tutorial. I think this can help you.

How to Create a UITextField to accommodate value in this following manner?

I am developing an ios application that has two input fields that for entering date. I am planning to add a UIDatePicker in the following manner
[_datePicker setFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-_datePicker.bounds.size.width, [UIScreen mainScreen].bounds.size.height-_datePicker.bounds.size.height, _datePicker.frame.size.width, _datePicker.frame.size.height)];
_inputText.inputView=_datePicker;
But the bigger problem is, I need it to look something like the image I have posted
How can I accomplish this?
Okay... there should be a couple ways to solve this.
1)
Put a transparent (or clear colored) UIButton over the view with the date labels. You may need to make the view containing the labels change color/alpha something to indicate the button has been touched before bringing up the date picker.
2)
If the above doesn't work, try adding the view with the labels as a subview into UIButton.

iOS Format Background

I am creating a simple quote app as a learning experience and need to format it to look better.
I am trying to make the background have a "white square" where the text is and make the text black. Just like the Twitter app has when you click on a tweet.
What is the best way to do this and what should I start with?
I know it is very simple, I'm only 15 and am trying to learn iOS. As you can see I have a server and have the app up and running, just want to format before I call it complete. Thanks! :)
-Henry
This will depend on how you created the label that displays your text, but you can do this very easily:
If you created your UI in a Storyboard / XIB file in XCode: assuming you dragged out a UILabel or UITextView, you can use the Attributes Inspector to set the text color and the background color (in the View section) of the element holding the text.
If you created the label (or text view) in code, you can set the textColor property and the backgroundColor properties programmatically.

How to write multiple lines in a label

I have a XIB file of type View XIB. In it I have a View controller, and in the View controller I have a label.
I have long text that I want to break, but it doesn't - it gets truncated.
I tried this solution - I did it in the attribute window - but it doesn't help.
You could use a TextView and disable the Editable and User Interaction Enabled options in IB.
use this
myLabel.lineBreakMode = UILineBreakModeWordWrap;
if you are worried about backwards compatibility use this because the comand i mentioned before was introduced in iOS 6.0
myLabel.numberOfLines = 0;
I have been running into a similar problem. I started out with a label, but wanted multi-lines and a UITextView worked great for this, at first. Because I am using a third party library (MBProgressHUD) to handle stuff like progress messages and what not, I had thread problems when trying to update a UITextView and show the progress message at the same time.
So I went back to UILabel which actually didn't have thread problems. I found a property to allow a specific number of lines of my choosing, and had to create the label big enough to display those lines. The downfall to this approach is that I don't get the context menus like Copy, Paste, etc. but more importantly I'm not running into thread problems. I can always embed this into a UIScrollView in the future if I so choose.
You could check out my category for UILabel on GitHub. https://gist.github.com/1005520
This lets you resize the height of the label to accommodate the content.
From the Attiribute inspector, choose LineBreaks->Word Wrap option when you have selected the lablel. Also increase the number of lines Label->Lines.
Try Following steps to solve issue :
Drag out a UITextView.
Double-click it to edit text, place cursor where you want the
paragraph break.
Option-Enter a couple of times to create a blank line & paragraph.

Resources