UITextview with zooming? - ios

how can i achieve UITextview with zooming facility?any tutorial please?

You can make simple UIWebView and it will be like UITextView, but with zooming.
This way has a lot of advantages. For example bold text, or italic. You will be able to use different fonts in one text.
Step by step guide:
create UIWebView
generate html string. For example: <html><head></head><body>My text</body></html>
load string in UIWebView

If I'm understanding your question correctly, you want a UITextView, and you want to allow the user to use two fingers to zoom in? If that's the case, when you add the UITextView in IB, at the bottom of the settings for the UITextView there is a check box for "Multiple Touch" just check that box and it will allow the user to zoom in. Hope I understood your question correctly.

If you not need user to edit text and just need to show some text with ability to change font attributes (i.e. size, weight) - use attributed string of text view. Then allow editing attributes and just call methods from UIResponderStandardEditActions protocol, like increaseSize: or decreaseSize: on UITextView. Before it you should set a range of text which must be affected:
self.textView.editable = NO;
self.textView.selectable = NO;
self.textView.allowsEditingTextAttributes = YES;
self.textView.attributedText = [[NSAttributedString alloc] initWithString:#"Lorem ipsum dolor sit er elit lamet..."];
Before calling increase/decrease method select all text:
//First select needed range
[self.textView setSelectedRange:NSMakeRange(0, self.textView.attributedText.length)];
//Then call increazing method
[self.textView increazeSize:nil];
Also you can call other methods of that nice protocol, which UITextView kindly implement:
[self.textView decreaseSize:sender];
[self.textView toggleBoldface:nil];
[self.textView toggleItalics:nil];
[self.textView toggleUnderline:nil];

Related

how to set different font size to text of button name in storyboard

I want to make application in which i want to make a login screen. It has button having name "Log inn with Facebook". I want font size of Facebook greater than Log in with. How can I set it in main storyboard?Can anyone plz help me?
Follow these steps-
1.Select button
2.Change its type to custom in Attributes inspector
3.Change its title from Plain to Attributed
4.Change the part of title which you want to be set bold
A solution would be to have a UIView with two different UILabel as subviews ( your "Log in with" label and your "Facebook" label ).
Then, above this UIView you could have a UIButton with a white background and an alpha equal to 0.01 so the button would be touchable but invisible.
This UIButton would be the functional part of your UI.
NSMutableAttributedString *titleText = [[NSMutableAttributedString alloc] initWithString:#"Login with Facebook"];
[yourbutton.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
// Set the font to bold from the beginning of the string to the ","
[titleText addAttributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName] range:NSMakeRange(0, 10)];
// Set the attributed string as the buttons' title text
[yourbutton setAttributedTitle:titleText forState:UIControlStateNormal];
Instead of creating NSAttributedString create NSMutableAttributedString then you can just set the string like this.

UITextField, set placeholder after text in ios

I need to keep the placeholder after the text, when click on the text box i need to clear only the placeholder and able to type characters.
In this Marissa is the name text and (First Name) is placeholder. Once i start editing placeholder need to clear and start editing complete text.
How can i achieve that?
I have found some similar custom textfield in the below URL. If you find this suitable, you can use it.
TUTORIAL / SOURCE
Please refer below code.
Just copy-paste below code in viewdidload()
textfield.attributedPlaceholder = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:#"Yourtext%#",Placehodertext] attributes:#{NSForegroundColorAttributeName: color}];
Assign Delegate of UITextfield to self.
textfield.delegate = self
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
textfield.text = #"Yourtext"
return YES;
}
You can not set place holder along with the text in a textfield.
But there is one alternate for this.
Textfields has something called left view which you can make readOnly view.
Try this :
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
UILabel *textLabel = [[UILabel alloc] initWithFrame:paddingView.bounds];
textLabel.text = #"Marissa";
[paddingView addSubView:textLabel];
textField.leftView = paddingView;
textField.leftViewMode = UITextFieldViewModeAlways;
Step 1:
Make the text filed attributed form xib and set the "Marisa (First Name)"
and change the color for the (First Name) as grey color .
Step 2:
And in the Textfiled DidBiginEditing method change the textField.text to "Marisa".
This could be achieved in several ways:
Use the attributedText property of UITextField instance to apply a styling for different parts of the text. Here you need to properly define the property each time a user has changed the input by using delegate methods or by observing UIControl Control Events.
If the structure of the text input is fixed and predefined you could use a batch of fields to imitate a more complex/smart field. Here, for example, you need to put two fields beside. One for the last name, second for the first name. Or you can use a combination of UILabel and UITextField if one the part is not editable. Such an approach allows you to configure a separate part of a complex field as you want: different placeholders, fonts, keyboard styles, etc.

Select specific text in UITextView to fire a segue

I’m trying to add a function to my application where the user can select a PRESPECIFIED text by me in order to fire a segue and get an explanation/information about what the user has selected.
The following text is an example:
Hawaii is the most recent of the 50 "U.S. states" and joined the Union on August 21, 1959.
The user can select "U.S. states" and will get information about U.S. states.
So Can I do that with Xcode or do I have to work with some html editing application? and if so, where would be a good place (online or book) to start learning how to do such a thing?
Thanks.
There may be better ways, but I know of one way to do what you're asking.
Create a NSMutableAttributedString with the text you want shown
Determine the range of characters you want to be clickable and using setAttributes:rangeSet, add the NSLinkAttributeName attribute with a value of a string you can use to identify the clicked region.
Create a UITextView and set the attributedString property to the string from above
Set some object as the delegate of your UITextView
Override the textView:shouldInteractWithURL:inRange: method. Return NO here, but do what you want with the URL, created from the string you used before.
Here's the code part. I'll leave the UITextView creation to you.
-(void)viewDidLoad
{
[super viewDidLoad];
NSMutableAttributedString *attString = self.textView.attributedText.mutableCopy;
[attString setAttributes:#{NSLinkAttributeName:#"123"} range:NSMakeRange(0, 10)];
self.textView.attributedText = attString;
self.textView.delegate = self;
}
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange
{
NSLog(#"%#", URL);
return NO;
}
You can do it in Xcode. You will want to create a segue in the storyboard and add an identifier to the segue. Then in one of the UITextViewDelegate methods, you can check the text in the text view. If it matches, you can call the segue programmatically using -performSegueWithIdentifier:sender:. Alternatively, you can create the entire segue programmatically using -segueWithIdentifier:source:destination:performHandler:.

iOS7 app and how to do app-wide font adjustments from within app (not in Settings)

I have a relatively small native app that and would like to have a 3-button control that can set the font size application wide. I'd like it to be able to support clicking the different unfilled-in size and have it automatically rerender the current view with the new font size and all subsequent views. Similar to having a control where the filled-in size is the current size and the clear versions would be buttons that could be selected:
It would seem like I want to pogramaticaslly have Dynamic Type but I'm not sure if there is an easier way. Reading through the different Text technologies really hasn't provided much help.
My views use a combination of UILabels and UITextViews with NSAttributedString's and NSString's. What would be the best option to manage font size programatically?
thx for any help
edit 1
Here's a label that I would like to add; can I just update the _mainFont variable which is used in the subviews and tell those subviews to update their rendering?
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 100.0f, 20.0f)];
myLabel.backgroundColor = [UIColor blueColor];
[myLabel setUserInteractionEnabled:YES];
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapAction)];
[recognizer setNumberOfTapsRequired:1];
//lblName.userInteractionEnabled = true; (setting this in Interface Builder)
[myLabel addGestureRecognizer:recognizer];
[tempScrollView addSubview:myLabel];
}
- (void)tapAction {
NSLog(#"Tap action");
_mainFont = MYLargerMainFont();
[self.view setNeedsDisplay];
//[self.view.subviews setNeedsDisplay];
}
The answers in the questions below might give you some ideas:
How to set a custom font for entire iOS app without specifying size
Set a default font for whole iOS app?
Is there a way to change default font for your application
How to set custom font family as system font in ios application
Just like Dynamic Type, it seems the best approach would be to fire a notification when the change happens, and have view controllers listen to this change and set the fonts. If you want something more robust, you could create subclasses of the UI elements you have and have them listen to font size change notifications, and update themselves accordingly. I like the former approach, because it is the view controller that should ultimately have control over the views.

Customising the Text Field

So - I am experimenting at the moment with app design.
This is my concept:
See the blue line? That should be where the users "cursor" starts and cant go negativaly behind that point, but can move positively until the end of the box.
As long as the UITextField starts after the colon and does not extend beyond the cell's trailing edge, you should have no issues. Are you laying out using code or Interface Builder?
I have done the similar UI using UITableview. Code to set the Username label for the cell in cellForRowAtIndexPath (use similar code for Password row):
tableViewCell.textLabel.text = #"Username:";
Here is the code to set the text field:
UITextField *textField = [[UITextField alloc] initWithFrame:textFieldRect];
//Insert code for text field delegate and properties e.g. keyboardType, autocorrectionType
tableViewCell.accessoryView = textField;

Resources