I'm looking for an UILabel with the following capabilities:
auto resize
support for breaklines
simple rich text formatting (bold,
italic, hyperlinks?)
I know I can do it myself, but I'd guess there should be already an open-source project for something like this, right?
I would recommend using TTStyledLabel/TTStyledTextLabel from the Three20 library. It provides the desired functionally and would save you the time of writing your own.
Related
I need to display rich text which may include a lot of images as is formatted as Markdown.
After some research I see that there are 2 most common approaches:
parse Markdown to HTML and display it within UIWebView
parse Markdown to NSAttributedString and feed it into UITextView which can use NSTextAttachments to display UIImages.
I'm wondering about possible issues with both approaches but mostly performance.
I'm aware that with UITextView I'm a bit limited as I can't use CSS to customise its look etc., but if you had some experience and there are a lot of issues with images alignment in UITextView that would be good to know too.
Additionally, as this may be relevant to others searching for possible functionality, I'm listing libs that I'm considering to use to handle Markdown:
AttributedMarkdown
Bypass
CocoaMarkdown
MarkdownTextView
With UIWebView you cannot get the frame size needed to display the content before it has been rendered (asynchronously). But with NSAttributedString you can get the bounds synchronously without first rendering the content. For this UIWebView is much slower.
I have used CSS with UITextView when converting HTML to NSAttributedString using DTCoreText. iOS has some own HTML to NSAttributedString conversion functions, but they are really, really slow.
Apple recommends the use of UITextView where possible
It’s recommended that you use a text view—and not a UIWebView object—to display both plain and rich text in your app.
Referene:
UITextView
Also to customize the looks you can use any RichText Libraries, like
SwiftRichString
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.
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.
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.