How to show a html string n uilabel in xcode - xcode

When I parse a URL, I'm getting the result in HTML format, so how to load that HTML string in UILabel or UITextView?

I believe this is not applicable for iOS as the AppKit.framework required is only for MacOS development.
Best solution to this problem so far seems to be the DTCoreText class available on GitHub.

Related

How to get iOS alert text in appium 1.6

Before upgrading to XCode 8 and subsequently Appium 1.6 and IOS 10 for some appium tests, I used to be able to use the below XPath to capture the main text in an alert.
#iOSFindBy(xpath = "//UIAAlert/UIAScrollView/UIAStaticText[2]")
private MobileElement alertText;
However something has changed and this no longer works. I would still like to be able to assert on the alert text and don't want to use the IOSMobileCapabilityType.AUTO_DISMISS_ALERTS capability.
Has anyone found a way to get at the alert text?
Bonus question: Where is all this XPath documented? I found it on some random forum, but I can't find any official documentation or figure out how it relates to a captured View Hierarchy in XCode.
Answering my own question in case it helps anyone else.
Due to the appium inspector not working with XCode8, the best way to print the screen layout XML is just to do a System.out.println(driver.getPageSource());
Then you can follow the structure and do something like
#iOSFindBy(xpath = "//XCUIElementTypeAlert//XCUIElementTypeStaticText[2]")
private MobileElement alertText;
I got that from this question: Finding elements by xpath in Appium using XCUITEST driver

Adding multiple Cib / Xib files in Cappuccino

Currently I'm working on a product that uses the Cappuccino Framework and the Objective-J language.
I created my project using this command after installing Cappuccino: capp gen -t NibApplication Myapp
The Problem I'm facing is that I want to keep my code and GUI clean.
By doing so I wanted to split the GUI up in separate Xib / Cib (compiled version Cappuccino can read) and separate controllers, like I do with iOS and Mac apps.
I couldn't find on the internet or on the docs how to do so.
Also, all the examples (including the NibApplication template) contains only 1 xib file.
In short what I'm after is to load a controller, based on a XIB file which holds the window. All the outlets are connected to the controller I loaded.
Is there anyone who knows how to do it?
Thanks in advance and have a nice day!
The typical way to do this is to use a CPWindowController or a CPViewController for each xib you want to load. Here's what it might look like:
var myViewController = [[CPViewController alloc] initWithCibName:"mynib" bundle:[CPBundle mainBundle]];
This would load Resources/mynib.cib from your main bundle. Normally you'd also subclass CPViewController so as to give yourself a convenient spot for your control code.
Fixed it myself! I used this tutorial: http://vimeo.com/8948460
But instead of using atlas I used XCode. Just follow the steps but with XCode and you'll be fine if you want the above to happen.

Is there a way to add custom fonts to Xcode to be available from a storyboard? [duplicate]

This question already has answers here:
Designing labels/text views with custom fonts in Interface Builder
(8 answers)
Closed 8 years ago.
I know how to add custom font files to be shipped with an iOS app. I can then customize the label font from code using code like this :
UIFont* font = [UIFont fontWithName:#"League Gothic" size:42];
self.topLabel.font = font;
My concern is that such customization will "infect" all of the project and may require some significant rework later on. Is there a way to include a font file into xCode itself, so it recognizes it and lets me select it from the storyboard font control?
You can find the answer to this question over here
Designing labels/text views with custom fonts in Interface Builder
You can find a link regarding the same topic here
http://www.abdus.me/ios-programming-tips/set-custom-fonts-in-interface-builder/
Hope this helps you.
Another way to achieve it without having to relay on exposing IBOutlets or adding external libraries is using categories and user defined runtime attributes from Storyboard or Interface Builder.
That way you can define your fonts in Storyboard or IB like this:
You can get the code required for the categories from this response.

Display WebArchive from Mail.app and Notes.app

Cocoa's WebView can display .webarchive files. The ones I try to display come from the pasteboard, e.g. when copying parts of a web page in Safari or Mail.app.
The issue I am having is that webarchives from Mail and Notes won't display in a WebView, while webarchives from Safari do.
I looked inside the data of those archives (BBEdit can decypher their binary plist format and show it as XML nicely) and found that the issue is caused by the unusual URL references Mail (and Notes) puts in there:
<key>WebResourceURL</key>
<string>x-msg://4/</string>
If I remove that entry or change it to something using http://, WebView suddenly can display such archives.
Now, how do I solve this in general in my code?
I don't want to have to decode the webarchive, find the WebResourceURL entry and remove it before passing the archive to the WebFrame for loading.
I wonder if there's something else I have to set up with either the WebView or its main frame to make this work.
I noticed that Xcode can show these webarchives just fine, suggesting that Xcode uses WebKit in a more "proper" way that solves the issue. But then, maybe that's just because it has NSWebFrame load the archive from disk, while my code loads it from a CFData object - when loading from a file, WebKit may be using that file URL as the base URL, while it only chokes on it when it doesn't get a usable URL at all.
I have created a little demo project for Xcode here: http://files.tempel.org/Various/Mail-WebArchive-Display-Issue.zip
It includes both an original archive from Mail ("mail-bad.webarchive") and a fixed one ("mail-good.webarchive"), both of which are displayed in two webViews in the demo app.
I had also opened a Tech Support Indident (TSI) with Apple DTS, and the responded that I should file a bug. The bug report can be seen here: http://openradar.appspot.com/radar?id=2843403
After brooding over what Xcode might be doing I found a solution:
This does not work:
WebArchive *archive = [[WebArchive alloc] initWithData:webData];
[[webView mainFrame] loadArchive:archive];
But this does:
[[webView mainFrame] loadData:webData MIMEType:#"application/x-webarchive" textEncodingName:#"" baseURL:NULL];
So, the explicit function to load the archive is faulty while the one that wants an explicit URL, even though I give it none, works.
Go figure.

Is there a syntax highlighting editor component for Mac OS X

I am looking for a syntax highlighting component that I can include in a Mac OS X XCode project to allow editing of Ruby, C++, Lua, etc.
I need a component that is open source or has the source included.
My Google searches didn't turn up much in the way of Mac OS X frameworks or components at all, let alone the type I am looking for.
Thanks for any pointers!
UKSyntaxColoredTextDocument (Mac-specific) or Scintilla (cross-platform and in use in a variety of editors, including Komodo) might be what you're looking for.
Try to use scintilla. http://www.scintilla.org/
You could try using CodeMirror. I do this in my SQLite Professional app to highlight user editable queries. It's also fairly simple to setup:
In your project, add the CodeMirror contents as a Folder rather than a group.
Add the WebKit.Framework to your project.
Add a WebView to your nib/xib.
Add the following code:
// Load our webview from our local CodeMirror path
NSURL * url = [NSURL fileURLWithPath: [NSString stringWithFormat:#"%#/CodeMirror/Demo/preview.html", [[NSBundle mainBundle] resourcePath]]];
NSString * html = [NSString stringWithContentsOfURL: url encoding:NSUTF8StringEncoding error:nil];
[webView.mainFrame loadHTMLString: html baseURL: url];
They also have lots of formats pre-defined, so it works quite well. The one issue I have found with this, is that the native Find dialog does not work when in the context of the WebView.

Resources