How to center a NSTextField in a view - objective-c

i've a NSTextField (label) centered with IB in a view with the text "__DRAG_AND_DROP_YOUR_MEDIA_HERE". In my controller a use NSLocalizedString to translate the text :
English.lproj/Localizable.strings :
"__DRAG_AND_DROP_YOUR_MEDIA_HERE" = "Drag & Drop your media here"
French.lproj/Localizable.strings :
"__DRAG_AND_DROP_YOUR_MEDIA_HERE" = "Déposer vos média ici"
Only the initial text "__DRAG_AND_DROP_YOUR_MEDIA_HERE" is centerred in the view. The translated text is not centerrd (depending on is lenght). All the translated text start at the same absciss x than the orignal text. How can i fix this issue ?
PS: I don't want to play with setFrame, height, width just for a simple point like this. I guess there's another method to do this.
Thanks.

Set the text field's alignment to NSCenterTextAlignment. You can do this from IB or programmatically using -setAlignment:.

Related

NSTextBlock backgroundColor is not drawn

I have an NSTextBlock subclass that has a specific backgroundColor set. Now when I add a custom paragraph style to a range of text like this
let block = MyTextBlock()
block.backgroundColor = myBackgroundColor
let pstyle = NSMutableParagraphStyle()
pstyle.textBlocks = [block]
attributedText.addAttribute(.paragraphStyle, value: pstyle, range: textRange)
// Append the attributed string to the text views textStorage ...
the text block is shown without a background color. I know that the text blocks works, because rectForLayout gets called, but when I try to override drawBackground it never gets called.
Do I have to do something else for NSTextBlocks to draw their background?
PS: Borders also seem to be ignored. I also tried to find a sample on Github, but that also doesn't draw any backgrounds, despite having a background color set.
After trying everything, I finally managed to get the background to show up, by setting
setValue(100, type: .percentageValueType, for: .width)
It seems that the drawing logic expects some value for the content size. Really nice documentation job there. This requirement is nowhere to be found.

Appcelerator: How to create Ti.UI.TextArea dynamically adjusting to content but with minimal height

I want to create a Ti.UI.TextArea object which would dynamically adjust its height to content but would have default height set (if no content). In Appcelerator if you don't specify height then it will automatically adjust its size to content but if there is no text then its size will be similar to textField. This is to small for me.
If you specify height property, then TextArea height won't change even if text will be longer than editable region.
I would like to have something like this:
var textArea = Ti.UI.createTextArea({
minHeight: 30,
});
or like this:
var textArea = Ti.UI.createTextArea({
minLines: 3,
});
I am looking for solution both for Android and iOS.
Is there any workaround for that?
You can change the height of the textField dynamically.
Add onChange event handler and change the height of the textField dynamically according to the number of lines in the text field.
Starting with 7.5.0.GA you can use maxLines on Android to be able to extend the TextArea to when pressing return. For iOS you have to create a work-around since there is no parity at the moment.

How to put UILabel.textColor in Interface Builder

I would like to put the font to my UILabel, i do it like this : myLabel.textColor = [UIColor colorWithRed:242.0/255 green:239.0/255 blue:236.0/255 alpha:1.0f]; My question is : how i can do exactly the same think with Interface Builder ? i know that i will use the inspector color in IB, but i don't know how to put the same think, for example how to put : red:242.0/255 in IB, and the alpha :1.0f ? thanks for your answers
place a label in IB,
go to Attribute Inspector -> Text Color-> Other
In colors window, Go to Color Sliders (2nd tab on top)
Click on Grey Scale Slider and change it to RGB Sliders.
There you can put R/G/B values as you have done in code.
You dont need to put like: x/255
just set Red as : 242
Alpha can be set between 0 - 1 with Opacity slider at the bottom 0 - 100.

color page's dot in a Titanium.UI.Scrollableview

Is it possible to use a custom color or image for the white dot of the pagingControl in a Titanium.UI.Scrollableview?
var scrollableView =Titanium.UI.createScrollableView({
views:[view1,view2,view3],
showPagingControl:true,
pagingControlHeight:30,
pagingControlColor:'transparent',
width : 200,
height : 90,
left : 120,
top:40,
maxZoomScale:2.0,
currentPage:0
});
Answer (as you said) found on http://developer.appcelerator.com/question/130397/color-pages-dot-in-a-titaniumuiscrollableview#227004 :
sorry, i dont have an example.. but here is it:
create a container view.
then create the small "dot" views, and add them to the container view. set the positions.
there is an event, when the scrollable view "scrolls" or changing.. and you can set the small dot view to active (of course you should set up the active state as well)

How to change textfield height for an ipad using interface builder?

We're using Interface Builder for developing an app for the iPad and we can't figure out how to increase the height of the textfields.
When we were using IB to develop an application for osx, you could go to the textfields attributes and under the control section you could set line break to word wrap instead of clip.
When we try to use Interface Builder for iPad applications though, it doesn't have the option of changing linebreak style under attributes-->control.
Is there any way to set the height using Interface Builder or do you have to set that in the code?
It looks like the height of the rounded-style text field is locked in Interface Builder. My solution was to use another of the UITextField styles in my XIB and then call textField.borderStyle = UITextBorderStyleRoundedRect in my viewDidLoad method.
Of course, textField should be the name of the UITextField IBOutlet.
iOS UITextFields are single line only and have a fixed height.
If you want a multi-line, variable-height text entry field then use UITextView.
1 - Right click on your storyboard/xib file and select "Open as" -> "Source code".
2 - Find the xml tag relative to your TextField, e.g.
<textField opaque="NO" clipsSubviews="YES" tag="102" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="6872" borderStyle="roundedRect" placeholder="Password" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Dxw-lR-kq5">
<rect key="frame" x="20" y="337" width="335" height="30"/>
3 - Change the height value to what you want (e.g. 50)
4 - Right click again on you storyboard and select "Open as" -> "Interface builder"
5 - See the result
there is a wrapping text field,that is what you need.
set the frame of ui textfield object in view did load but it will involve coding
[self.searchText setFrame:CGRectMake(180, 450, 400, 250)];
//in my case the object was called search text...
You can edit the height of any UITextfield in IB.Just set the constraint in IB.Select the constraint.In the Size Inspector-->Select and Edit just change the constant to your desired value.Press Enter ...Done!!!! (Can't get multiline though)