I'm having a button to change the normal text to bold text in the label of my UIView. In UITesting, How to assert that the normal text changed to bold text when i pressed the button?
let app = XCUIApplication()
let label = app.staticTexts["myLabel"]
app.buttons["Bold"].tap()
XCTAssertEqual(label.value as! String, "Hello")
You cannot do it. As XCUITest is functional test, if you want to
assert visual requirements like font, colour, you should write a unit test insteads.
I don't think there is a way to acess UI components (or whatever members of UIKit, including UIFont) over XCUIElementAttributes protocol (what is used for passing accessibility information for XCTest environment).
However you are free to write whatever you want in accessibilityValue or accessibilityLabel properties and read them afterwards. For me it's the only way to get round XCTest limitations when needed (however it will corrupt accessibility user experience, so you should take it into account)
Related
I want my code to add custom words like 'nooooober' into my iphone dictionary. I write below code. But Still UItextField auto-fill is not showing me 'nooooober' word in autofill options.
Here is my code, written in DidFinishlaunching of appdelegate
if (UITextChecker.hasLearnedWord("nooooober")){
UITextChecker.learnWord("nooooober")
}
Thanks,
Aaban.
Text display and fonts UITextChecker works in the context of a single piece of text, like a document.
So any words that you ignore/learn aren't added globally for the device, just the current context that it is being used on. You wont be able to 'learn' words in your app and then expect auto-fill to use them in another app, such as Messages
How do I change the size and colour of the flashing cursor in my textfield using my storyboard for my Mac app.
I assume I have to connect it into the view controller script (control drag) and edit some uitextfield color parameter for the cursor?
But I don't seem to be getting anywhere fast. I am working in swift 2.2 with Mac app Storyboards. Like Ulysses and Taskpaper.
In Swift 3:
Change YOURTEXTFIELD to your textfield and you are set:
(YOURTEXTFIELD.value(forKey: "textInputTraits") as AnyObject).setValue(UIColor.black, forKey: "insertionPointColor")
Documentation: https://developer.apple.com/documentation/appkit/nstextview/1449309-insertionpointcolor
Search for _drawInsertionPointInRect that's the private method that you need. Though you also need some other stuff I think... but it's all mixed into my code so I can't say for sure what it all is. Anyway search for _drawInsertionPointInRect and you'll get to some explanations.
How can I check the spelling of a NSTextField using swift? I'm already using controlTextDidChange to validate the text. This solution seems to mention casting the first responder as a NSTextView but I'm not sure that is possible with swift using coercion. I know this would be easier if I changed to a NSTextView but if possible I'd like to avoid this.
This should help you out.
// Focus TextField
phraseTextField.becomeFirstResponder()
// Enable Continous Spelling
let textView: NSTextView = (self.window!.firstResponder as! NSTextView)
textView.continuousSpellCheckingEnabled = true
Adapted from: How do I enable spell checking within an NSTextField on Mac OS X?
In other situations, it may just work better to change NSTextFields to NSTextViews. Simply use a "Text View" (search NSTextView in the Object Library) and spell check will be on by default. NSTextFields simply do not support spell check in some cases, as best I can tell.
Also consult: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextView_Class/#//apple_ref/doc/uid/20000373-SW55
If you want to make a multilingual button on a native iPhone app, where it can be one language by default, but based on your settings, show different text on the same button, how would you go about it?
Is it also possible to style (e.g. with text-shadows and custom fonts) the text on the button?
I'm not an iOS developer, but I'm attempting to provide designs for an iOS developer and don't understand the limitations (yet) when going from CSS3 to iOS UI elements.
So far, iOS development appears to be like creating image-maps where none of the CSS logic is applicable from web development and almost all UI elements appear to need all states as flattened images. I thought the controls were more dynamic but haven't found the right terminology for results from google to be very forthcoming on the topic.
U can use NSLocalizedString for multilingual text on button.
Configuring Button Title
titleLabel property
reversesTitleShadowWhenHighlighted property
– setTitle:forState:
– setTitleColor:forState:
– setTitleShadowColor:forState:
– titleColorForState:
– titleForState:
– titleShadowColorForState:
Also set Custom font like this:
yourButton.titleLabel.font = [UIFont fontWithName:#"Courier" size:22.0];
if u want to add gradient to button then u will have to use CALayer like this:
yourButton.layer = //any modification in button's layer here
For more refer UIButton class reference
I have a text which looks like the following,
the url of the page is http://www.myurl.com, and the phone # is (999)999-9999, blah blah blah...
And I want to show it in a way such that the URL and the phone # are both in different color and bolded. Can I do it using just one UILabel control, or I need to parse them out and put them onto separate UILabel controls. (Note that the text itself could span multiple lines.) How can I do it?
Sorry I forgot to mention that this is for iPhone (CoCoa Touch), where the NSAttributedString is not available.
You might want to check out TTTAttributedLabel. It supports automatic data detection for things like Phone Numbers and URLs, as well as mixed styles with NSAttributedStrings.
You could use an NSAttributeString to decorate your string. There is a good explanation of how to use them here Change the background color of a substring of a drawn NSString?
You could try using a UIWebView, which detects both URLs and phone numbers.