Font and Font Size Changing - objective-c

I have a Mac app with a plain-text text view. I have been able to get it to save, etc, but when I change the font or font size in my app using the font panel, it is not saved when the app re-opens.
How can I create a way that my app will save the font and font size changes? Thanks!

Save Font and Font Size in NSUserDefaults and load from NSUserDefault at the time of application launching.
NSString *valueToSave = #"someValue";
[[NSUserDefaults standardUserDefaults]
setObject:valueToSave forKey:#"preferenceName"];
to get it back later
NSString *savedValue = [[NSUserDefaults standardUserDefaults]
stringForKey:#"preferenceName"];
Take a look at Save string to the NSUserDefaults? post.

Related

Unable to save pdf form data using PDFKit iOS 11

I have loaded a pdf form using PDFKit in iOS 11. I am trying to save the editable fields ( Checkbox, TextBox) values.
How do I get back the editable PDFDocument object to save the PDF contents using
(BOOL)writeToFile:(NSString *)path;
Thanks. I did something like this. I added and Observer and on receiving notification when the pdf changes write the contents to a filepath
PDFView *view = notification.object;
PDFDocument *myDocument = view.document;
NSData* content = myDocument.dataRepresentation;
[content writeToFile:newPath atomically:YES];
That worked for me.

UINavigationBar custom font not working on iOS 8

I've spent some hours trying to use a custom font for the navigation bar title on iOS 8. This works ok on iOS 7:
UIFont *font = [UIFont fontWithName:#"Gotham-Bold" size:12];
NSDictionary *textAttributes = #{ NSFontAttributeName: font };
self.navigationController.navigationBar.titleTextAttributes = textAttributes;
But on iOS 8 the text simply disappears. Changing the color, or the system font size works perfectly, but trying to use a custom font won't work at all. Anyone has any idea on this?
Thanks!
EDIT
I've created a small project so you can try it yourself:
https://github.com/noquepoaqui/customHeaderFont
These lines of code are on MasterViewController on line 30.
You have a typo when you assign the attributes:
It should be:
self.navigationController.navigationBar.titleTextAttributes
instead of:
self.navigationController.navigationBar.TitleTextAttributes
If that doesn't fix the issue, you can test if the font was added correctly by placing this code in the AppDelegate's didFinishLoadingWithOptions. This will print all available fonts of your app. Just look at the output window and search for your font name (Gotham-Bold). If it's not listed you can delete the font from your project and add it again via drag & drop. Make sure to tick "add to target" next to your app in the dialog that appears.
//list all available fonts
for (NSString *family in [UIFont familyNames]) {
NSLog(#"---------- %# ----------", family.uppercaseString);
NSArray *names = [UIFont fontNamesForFamilyName:family];
for (NSString *font in names) NSLog(#"%#", font);
}
The .ttf font i was using was not working well. I've installed the .otf version and everything works well.

Setting size to custom iOS font doesnt work

I am using some custom fonts in my iphone app. They are displayed correctly, but i cant change their size.
Here is how set this font for UILabel:
myLabel.font=[UIFont fontWithName:#"Cabin-Regular" size:18];
This label is part of uitableview cell, if that could play any role.
Label settings in IB:
I change only color, text and font in code for this label.
What could be wrong?
Are you sure the font is loaded correctly?
You can try:
for (NSString *familyName in [UIFont familyNames]) {
NSLog(#"%#", familyName);
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(#"\t%#",fontName);
}
}
This will show you all the fonts that are loaded. Make sure the same name "Cabin-Regular" is showing up exactly the same. A lot of times the font itself isn't loaded and then the font-size won't be used at all.
You need to add your font in your Xcode, if you are adding manually.
Add your font in your project files
Go to your Project name-Info.plist file, right click and click Add Row.
In your new row type Fonts provided by application. If you expand it you can add new items, in there add value to item 0 . The value should be your font file name. like below image
4. Double click on your font, it'll open in external editor, like following image
5.Give that name into your fontWithName: method. If you are setting value to your tableviewcell. the code will be
cell.nameLbl.font = [UIFont fontWithName:#"Cabin" size:18.0];
It works fine for me. I hope it helps :)

How do you save a picture with NSUserDefaults?

I have a iPad app that can take a picture and then put it within a image view. How do I go about saving the pic that I have stored in the image view? Here is what I have tried so far: [imageView setImage:[[NSUserDefaults standardUserDefaults] objectForKey:#"storedImageValue6"]];
Pretty much you have to convert it to NSData and vice versa. Take a look at this link: Save images in NSUserDefaults?
Here imageSet is UIImage
NSData *imagedata=UIImagePNGRepresentation(imageSet);
[[NSUserDefaults standardUserDefaults] setObject:imagedata forKey:#"Theme Selecting"];
[[NSUserDefaults standardUserDefaults] synchronize];
You can use this code for saving image

how to save textcolor on textview by using NSUserdefaults

I am the beginner of iphone developer,my problem is how to save the textcolor on textview.
i want to taken 3buttons in each one set one color.when i tap the button.what the button had color text write on textview and at the same time save the feature also.when i open the application it does not lose the old feature.so how can solve the problem please help me.
thanks...
You can archive any object and store it in user defaults. To set it:
NSData *colorData = [NSKeyedArchiver archivedDataWithRootObject:color];
[[NSUserDefaults standardUserDefaults] setObject:colorData forKey:#"color1"];
And to retreive it:
NSData *colorData = [[NSUserDefaults standardUserDefaults] objectForKey:#"color1"];
UIColor *color = [NSKeyedUnarchiver unarchiveObjectWithData:colorData];