How can I set a special character(right arrow) in UILabel? - xcode

I am trying to set a text in UILabel, like this
mylabel.text = #"▶ section1";
but, the right arrow character is translated to audio player icon inside UILabel.
Is there a way to print right arrow character intactly as it is.
Thank you.

Try using unicode:
mylabel.text = #"\u25BA section 1";

Related

Stop highlighting text in NSTextField after pressing enter key (alt: jump to end of line) [duplicate]

I have a NSTextField with some text "sometext". How can I place the cursor between e and t: "some|text" programmatically?
You need to set your text field current editor selected range property. Try like this:
textField.currentEditor()?.selectedRange = NSRange(location: 4, length: 0)
You will need to call displayIfNeeded
textField.displayIfNeeded()

Xamarin.iOS UIBarButtonItem With Unicode Character as Title

With a Xamarin.iOS project, I'm trying to use a Unicode character (gear icon) for the left bar button item in my top menu. I could use a custom icon for this, bit I read on some iOS posts here on SO that you can also use Unicode characters. So I followed an example, translated form Swift and it all works fine, except that my button title is always the literal Unicode string instead of the decoded gear icon.
Also, the code below will not build because that string ("\u{2699}") needs to be escaped. I've used \ and # escaping methods but I always end up with just the literal string in my button. Any ideas what I'm doing wrong?
var ltButton = new UIBarButtonItem();
ltButton.Title = new NSString("\u{2699}", NSStringEncoding.UTF8);
ltButton.Style = UIBarButtonItemStyle.Plain;
var font = UIFont.FromName("Helvetica", 18.0f);
ltButton.SetTitleTextAttributes(new UITextAttributes { Font = font }, UIControlState.Normal);
this.NavigationItem.SetLeftBarButtonItem(ltButton, true);
This is all you need:
ltButton.Title = "\u2699";
ltButton.Title = "\uD83D\uDE03";

How do I limit NSTextView to 2 lines?

I'm trying to specify the number of lines for NSTextView. My designer is requesting 2 lines of text max. I've tried NSMutableParagraph style to add the ellipses truncation that I want, but with NSMutableParagraph I can only get NSTextView with 1 line and without NSMutableParagraph, I get a scrolling text with as many lines as needed to complete text.
var attributedString = NSMutableAttributedString(string: "This is my text, I can keep going for many characters")
var para = NSMutableParagraphStyle()
para.lineBreakMode = NSLineBreakMode.ByTruncatingTail
let globalAttributes = [
NSParagraphStyleAttributeName: para
]
let range = NSRange(location:0, length: attributedString.length)
attributedString.addAttributes(globalAttributes, range: range)
cellView.myTextView!.textStorage?.setAttributedString(attributedString)
I've tried height constraint on NSTextView. I've tried:
cellView.myTextView!.textContainer?.containerSize = NSMakeSize(300, 32)
I've tried creating IBOutlet for NSScrollView that NSTextView in within and adjusting its height. No luck with getting both 2 lines and truncation. Any help is greatly appreciated. I feel like I'm just missing a method or setup. Thanks!
From 10.11 you can use this
yourTextViewObj.textContainer.maximumNumberOfLines = 2;
You can use an NSTextField configured as a multi-line label. That means setting its cell's wraps property to true and, if desired, its truncatesLastVisibleLine to true.
For NSTextField (aka label) You can just do self.textField.maximumNumberOfLines = 2;
That's it.
Max number of lines is now a property of NSTextField
label.maximumNumberOfLines = 1;

UITextField not scrolling horizontally

I am trying to make a small calculator app.
When a UIButton is pressed, the Button title is added to a UITextField.
kind of:
myuitextfield.text = [myuitextfield.text stringByAppendingString:[button currentTitle];
When I reach the end of my textfield, the text gets truncated. How can I disable this, so the textfield starts scrolling automatically and allows adding more characters?
I tried every possible option in Interface Builder, without any luck.
Isn't the UITextField supposed to scroll automatically? I can see this behavior when a native keyboard is used and text is entered.
I have chosen UITextField, as I need only 1 Line.
To illustrate the Problem:
When I enter text using my custom UIButtons text gets truncated
When I tap the UITextField and enter text using the keyboard I can enter unlimited text and the text is not truncated.
If you are facing this issue on iOS7, I've managed to fix it after been inspired by this post. In my case I had a field for entering an email address and after reaching the edge, the user could carry on typing but the text would be invisible (off-field).
First, add a callback to your UITextField so that you can track a text change to the field:
[self.field addTarget:self action:#selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
Then evaluate the size in pixels of the entered string as it is typed and change the text alignment from left to right when reaching the edge of the field area:
- (void)textFieldDidChange:(NSNotification *)aNotif{
float maxNumPixelsOnScreen = 235; // Change this value to fit your case
CGSize maximumSize = CGSizeMake(maxNumPixelsOnScreen + 10, 1);
NSString *aString = self.field.text;
CGSize stringSize = [aString sizeWithFont:fieldFont
constrainedToSize:maximumSize
lineBreakMode:NSLineBreakByWordWrapping];
self.field.textAlignment = NSTextAlignmentLeft;
if (stringSize.width >= maxNumPixelsOnScreen)
self.field.textAlignment = NSTextAlignmentRight;
}
Note:
self.field is the offending UITextField
maximumSize: I'm adding 10 the the width to be slightly over the limit defined
fieldFont is the UIFont used to render the text field
Hope it helps!
you have to add UITextview and limit the number of lines to 2.Textfield doesnt work with two lines.Textview is same as textfields except the delegates and some properties differ.

Set value to label with a text field

I want to make an app that allows the user to enter a value in a text field and from that, it should change the value of a label. I'm new in programming so I don't really know how to code it. In the .m file how should I connect the text field's value to the value of the label?
Thanks in advance
Bind your textField to this method
– textFieldShouldEndEditing:(UITextField*) txtField
{
[labelField setText: [textField text]]
return YES:
}

Resources