I want to create UIImageView with some system-image in it. (Example: the disclosure chevron image, etc.). How can I do so programmatically?
Note: I don't want to download the image and add it to the project, I want to fetch it from the user programmatically / from the Interface Builder.
From iOS 13 and Xcode 11 you can get system images by giving system name.
let image = UIImage(systemName: "info.circle")
Reference : UIImage Apple Documentation
If you mean you can to set the button to use the system disclosure icon, just do as #middaparka suggested and use this:
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
If you're asking how you can access the image directly, you can't do that. This is your only option: Use default apple icons for pdfs and docs in iOS app?
I think iOS-Artwork-Extractor is the tool you are looking for. It lets you extract the artwork into png files.
There is no clean programmatical way to access the images of system buttons. Quote from the documentation of the UIButton.imageView property:
The value of the property is nil for system buttons.
You may do an off screen rendering of the views and extract the resources on the fly but that's a very shaky approach. It's better to extract every asset you need and use them as intended. You'll suffer much more in the end with the programmatic way.
Related
In the storyboard of XCode 11.5 there are several icons in the "image" property of a UIButton. However, I can't find any references to these images in the documentation and when attempting to create a button programatically I can only find references to using images I put in the bundle myself. Is there a way of accessing these built-in images from the code? How?
They are SFSysmbol icons. If you're asking about an auto-complete in Xcode when adding images programmatically, there isn't one. But you can get the list of all the available SFSymbols from this app. And you can use UIImage(systemName:) initializer to access the available icons.
To access system icons:
let image = UIImage(systemName: "wrench")
button.setImage(image, for: .normal)
I wanted to make a kind of a notes app where users can add images inline with text, similar to how iOS' native Notes app does. Any advice on approaches I could take for this?
I'm new to iOS development and have been trying to teach myself a bunch of necessary skills and was curious as to how someone would go about doing this.
Thanks!
You can use UITextField to add images and text in one field, It can be done by using storyboard also and to do it programmatically is also convenient. Find the below code to add image programmatically in a text field :
var imageView = UIImageView()
var image = UIImage(named: "email.png")
imageView.image = image
emailField.leftView = imageView
emailField.leftViewMode = UITextFieldViewMode.always
emailField.leftViewMode = .always
UITextView is your best bet. It is not the most friendly UI component to work with if you are just starting out, but it is what Apple almost certainly uses for their Notes App, and supports inlining of text, images, hyperlinks, styles etc.
Like in UIButton or a UIImageView etc..
If so how do I do that using the StoryBoard or in a Xib
I am able to use the default icons inside UIBarButton items but cannot look them up in normal buttons . A solution using Storyboard would be really nice
In order to use them you need to extract them using a handy little app called (fittingly enough) iOS Artwork Extractor. I use it all the time when I want to mimic iOS system behaviours.
Download the Xcode project at:
https://github.com/0xced/iOS-Artwork-Extractor
Or another way:
The Other.artwork file is in /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/ (you need the SDK).
Use the "iPhoneShop-1.3.jar" program -- available currently here to extract all of the images into a directory.
java -jar iPhoneShop-1.3.jar ARTWORK Other.artwork EXPORT Other
No you cannot use UIBarButtonItem on other as subview like UIButton. UIBarButtonItem can only over UINavigationBar.
I can't seem to figure out how to programmatically set a new image, via the outlet, and make it start animating.
Sequence
zeroEntering0.png
zeroEntering1.png
zeroEntering2.png
zeroEntering3.png
zeroEntering4.png
I imported the sequence of images into the Image.xcassets inside the WatchKit App
I can set the image in the interface builder to "zeroEntering" and set animating to "Yes" and it works correctly.
However, I want something more dynamic, I need a button press to choose a new animation sequence and start it off. If I try and set the image programmatically using the same name from the interface builder, the UIImage is nil.
What naming convention should I use when programmatically setting the UIImage? "zeroEntering", "zeroEntering0", "zeroEntering.png" or "zeroEntering0.png"
I tried using the two non-nil options and the image did not animate and went black.
The answer is subtle and definitely got my wheels spinning for too long.
According to this beautiful article,
You should use setImageNamed(:) when the image you want to display is either cached on the watch on is in an asset catalog in the watch app’s bundle, and use setImage(:) when the image isn’t cached — this will transfer the image data to the Apple Watch over the air!
So, I kept my images in the assets catalog on the watch app, and switch to use,
[self.testImage setImageNamed:#"zeroEntering"];
[self.testImage startAnimatingWithImagesInRange:NSMakeRange(0, 4) duration:0.2 repeatCount:100];
Set the image as [UIImage imageNamed:#"entering"] then call startAnimatingWithImagesInRange:duration:repeatCount:
Check it out here: https://developer.apple.com/library/prerelease/ios/documentation/WatchKit/Reference/WKInterfaceImage_class/#//apple_ref/occ/instm/WKInterfaceImage/startAnimatingWithImagesInRange:duration:repeatCount:
Make sure to follow the tips here: https://developer.apple.com/watchkit/tips/
I was wondering how I should go about using high definition tab bar icons if my tab bar icons are being set programmatically. I'm pretty much just doing the standard:
tabBarItem2.image = [UIImage imageNamed:#"ExploreIcon.png"];
Will putting two images in my supporting files named "ExploreIcon.png" at 30x30 pixels and "ExploreIcon#2x.png" work without using additional code? Thanks for the help!
You don't need to specify the retina version, the system will use the higher resolution version if present in the bundle. Also you don't need to add the extension
[UIImage imageNamed:#"ExploreIcon"];
the two images should have te same name for example :
ExploreIcon.png
ExploreIcon#2x.png
You need not consider choosing file which fits and displays better on a specified device, Let iOS do that for you.
Just keep files to support all possible devices.
Follow:
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix.html
tabBarItem2.image = [UIImage imageNamed:#"ExploreIcon.png"];
This is good enough. Just make sure the file names are appropriate. i.e.
you have to add an imageview and set the cgrect size 40*40 and than you will add that image view on the tab bar icon image.