One of the most common problem faced by iOS developers is to change the font of all the UI elements in one go.
With the introduction of UIAppearance Protocol setting the font did become very convenient, since then I've been using appearance to achieve this.
I was going through this tutorial trying to understand Text Kit introduced in iOS 7. The tutorial uses subclass of NSTextStorage to beautifully format the text.
Now I was just wondering if it is possible to change the font of UI elements by subclassing the NSTextStorage. I spend few hours trying to figure out where to start from but couldn't achieve anything so far. I appreciate if any one can give me a hint to where to start from and some tips to get this done.
I welcome all your suggestions and views on this.
Related
I'm attempting to render content both in a UILabel as well as in a WKWebView containing Urdu text. For display Noto Nastalique is used. However, it seems iOS has issues computing the correct spacing/ligature.
Using text from http://behdad.org/urdu/ as a test subject UILabel renders
while WKWebView renders (notice the glyphs overlapping)
In this small example the problems are most obvious in WebKit, but there are similar issues when wrapping text in UILabel. I'm hoping someone has faced and solved similar issues, or could point to information on best-practices for displaying Urdu content.
Example project can be found on github
I believe it is a problem with "Google Noto Nastaleeq" font on iPhone. Apple did try to implement in iOS 9. They had the similar problem.
Have you try to implement Jamil Noori Nastaleeq? Read my guide there I noticed Jamil Noori Nastleeq typeface don't have that kind of rendering issue.
For a reference please read my article that how I was able to make it so. https://medium.com/#mmudassir/nastleeq-and-ios-8-love-story-bit-broken-7cc2311fc784?source=linkShare-563fcf255dda-1461862616
I want to style a label. Nothing crazy, just some coloring, changing of font-sizes for specific words, etc. I can do this with NSAttributedString, but would it be possible/better to do in TextKit, newly introduced with iOS 7?
I've looked around, but TextKit doesn't yet have a ton of tutorials, and none seem to address this.
It should still be done with NSAttributedStrings as the parameters you've listed exactly describe the attributes of strings. NSTextStorage is a subclass of NSMutableAttributedString but it's not intended for what you want to do (I think this class might have misled you).
Using Text Kit to Draw and Manage Text contains a nice overview of Text Kit objects, I highly recommend reading it.
We want a native rich text editor because we are trying to stay away from using Javascript and webviews for this solution.
We've tried many things so far, and we're left with quite a few obstacles that we just can't get around. Let me break it down into questions that I hope you can answer.
I have a UIButton, that says "B" on it, and I want to put it into the 'selected' state when a user sets 'Bold' from using the TextView's long-press gesture on a selection. How do I register for this state change? I tried adding an observer on the textView.attributedText, but it doesn't seem they are changing that dictionary, but instead are updating it. NSDictionary has no way, as far as I know, to add observers on the dictionary's keys. So I'm stuck with noticing this change.
Regarding number 1, I also tried setting the textView's inputDelegate and it seems that the method - (void)textDidChange:(id )textInput never gets called. :( Docs says is should. What did I do wrong?
How do I update the attributedText weight when I hit my bold italic or underline button.
How do I convert my attributed text into HTML?
I saw a few neat libraries for number 4, but I'm still curious what you'd come up with. (Broadens my options). But, I can't really work on number 4 until I figure out how to do the previous 3.
This editor will also need hyperlinks, bulleted lists, and numbered lists, more things I imagine I'll struggle through, but if you could answer the 4 questions above, that will keep me held over for a while. :)
Thanks!
Here is a link to an iOS rich text editor I've been working on.
https://github.com/aryaxt/iOS-Rich-Text-Editor
There is still a lot of work that has to be done, but the basic features are there.
The Apple sample application called 'TextEdit' does much of what you've described and, if not that, would be a very good starting point. Find the sample code with a search in the Organizer.
There is a commercial editor based on the DTCoreText library. I've used that library but not the rich text editor. Look at the Cocoanetics web site. It's not cheap but will save you a ton of work.
Simple question. Does anyone know why Interface Builder doesn't allow for applying custom styles on UI elements? Why is it only possible to do this programmatically?
I can see how this might be difficult for custom UIView subclasses but the default controls definitely only have a tiny subset of the style options available through IB, such as background color or changing font colors. Why is this the case? Is there any way to approach a concept like application themes through IB?
My personal feeling is that Apple does this right. They provide the elements and styles that fit the HIG. If they start adding other elements/styles then where do the start, and where do they draw the line?
Also, it isn't like Apple actively prevents using custom elements/styles, they just don't include it in the tool set.
The last thing we need is a tool set full of bloat.
You'd really have to ask Apple as to the why. I'd guess that it's some combination of promoting consistent use of standard interface elements and limited development resources.
You can, of course, build interfaces using your own custom subclasses of the standard interface elements in IB. It's a little more work, since you have to change the type of each object you add from UIButton to MyGreenButton or whatever, but it's not difficult.
It's also not hard to imagine coming up with a controller-type class that could connect to all your controls and whatnot to customize their appearance in some consistent, theme-like manner. Add an instance of that to each nib, connect all the controls, and let it do it's thing. You wouldn't see the effect until you actually run the app, of course, but it sounds like you're talking about customizing colors and fonts rather than size.
Unfortunately you are at the mercy of the Almighty Apple Deity..... Bow at their feet and give thanks that you have what they give you..... lol...
Seriously tho. Apple puts in what apple wants and you can request additions, but the IB is fairly minimal in the way of features.
I think this may be by design. Somehow an Elegant Simplicity ?
The ability to customize the controls is given to the programmer however I think they want the controls standardized. I just dont know why they didnt give a little more variety in the controls that are available. Like a few more button styles for the ios devices...
If you find out otherwise I would definitely be all ears.
I think that apple should let you to customize more the controls, for games it takes too much time to make the custom control ( you can make it faster in android as you can configure it in xml)
Btw PaintCode is another option to make your own style for components, it will generate the code but its more like interface builder
http://www.paintcodeapp.com/
I'm currently scoping out a project for the iPad which is rather text and font heavy. There are many pages of styled text, which also need custom fonts. I have toyed with the idea of simply rendering PDF or PNG files on-screen, but I think we need to be able to dynamically repaginate the text.
We've used UIWebView in a previous project quite successfully, however there are a few things I don't like about it... Firstly, you have to hide all the silly drop shadow elements to stop them showing when the user scrolls beyond the bounds, and we had to add some JavaScript to find out actually when a page had fully loaded. Overall, the experience seemed a bit clunky, as well as worrying if the project could potentially break if Apple decided to update the subviews...
The other thing we've been looking at is Core Text, which looks very powerful. The only worry with this is that it appears to be a rather steep learning curve for us since we've mainly been working in UIKit (with a bit of Core Graphics). I couldn't even work out how to change the size of the font after a morning's work.
Are there any other alternatives*? Should I stick with Core Text? Is there any way of using UITextView with multiple fonts and styles?
Thanks!
:-Joe
EDIT: *by alternatives, I am really looking for built-in iPhone SDK alternatives only please... I would rather not mess with third party frameworks because I don't have the time... Thanks :)
You could use Pango, which uses CoreText when on iOS.