Adding Text and Images in the same field in Swift - ios

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.

Related

How can I assign one of the built-in icons to a UIButton programatically?

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 need font with centered plus sign

Hello I'm making the Add button for my iOS project. It has to use material style, so i've found BFPaperButton project on github. Now I need to find font where plus sign is vertically and horizontally centered. I've try many fonts, but not all. The most suitable is Times New Roman. Maybe someone now better font for my goal? I think if UIBarButton System items have their font - Add symbol has to be suitable, but I can't find it.
P.S.: Text in button centered
Here is an image of what I already have.
https://pp.vk.me/c622128/v622128875/1e805/D5K67mtyA50.jpg
And what I have to make
https://pp.vk.me/c622128/v622128875/1e80c/y0_W11kTl-0.jpg
P.P.S. I'm sorry for my English, I'm trying to write question without any translators.
Just used
contentEdgeInsets = UIEdgeInsetsMake(-12, 0, 0, 0);
It helped.

Using svg or font icon in the ios applications

In my iOS application we need to change the color of the icons based on the user configuration. It is one of our important business option.
One of my friend advised me for using .svg or font icon. And shared me this link
They are creating web applications while I am developing iOS application. Does iOS support this technique too? If yes, how can I use it?
Edit
I found SVGKit that is used for the iPhone/iPad apps. Is there any binding library for using it on the monotouch?
SVG fonts (paths) are kind of easy to convert into source code. Once you have this it's very simple to render them in different colours, sizes (iphone/ipad) or resolutions (e.g. retina).
That's what I did here. That's for an older version of FontAwesome, but it could be used as is (or updated to the latest) for your application.
you can use FontAwesome+iOS
all the icons available here: link
If you just need to change color of icons, you probably can solve this without svg. Just use tint colors.
Create a template image:
let templateImage = UIImage(named: "bla_bla")?.withRenderingMode(.alwaysTemplate)
Then add it to a button or an image view and set the tintColor:
button.setImage(templateImage, for: .normal)
button.setImage(templateImage, for: .highlighted)
button.tintColor = UIColor.blue
This solution works only for monochromatic icons!
Besides, if you want .svg, you can use WKWebView, it's really fast and will not cause overhead if you have limited amount of icons.

How to get system images programmatically? (example: disclosure chevron)

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.

invert UIDatePicker colors in iOS 7

I want to start by saying that i would post this question on the Apple Dev Forums but because of the hacking attempt fiasco , or whatever that was, the forum has been offline for almost 2 weeks now and i need a solution for this as soon as possible.
In iOS 7 the UIDatePicker looks like this :
and a client asked to look like this :
(basically inverted).
I've tried a few things:
Setting the background to black and looping through all the view's subviews until i reach the labels that show the date itself and change their color to white. The problem is that The view has only one subview, and that subview doesn't have any subviews of it's own. So this solution doesn't work. (it did in ios6).
Applying a filter to the view's CALayer. The thing is that this is only possible on OS X not on iOS, for some unknown reason.
Playing with UIApperance protocol. From what i've read this should work but what i've tried didn't and i don't have extensive experience with this to figure out why not.
Any ideas what i can try? Is this even possible? Did i made a mistake in my approach of the problem?
Try this out :
Put this code in -(void)viewDidLoad
[datePicker setValue:[UIColor whiteColor] forKey:#"textColor"];
Swift:
datePicker.setValue(UIColor.white, forKey: "textColor")
Don't know if this is still relevant but on Swift 3 / Xcode 8 you can simply do this:
let datePicker = UIDatePicker()
datePicker.datePickerMode = UIDatePickerMode.date
// Sets the text color
datePicker.setValue(UIColor.white, forKey: "textColor")
// Sets the bg color
datePicker.backgroundColor = UIColor.black.withAlphaComponent(0.6)
textField.inputView = datePicker
I spent quite a bit of time struggling with the same problem. At first, I've put a UIDatePicker on a black background and was wondering why it is invisible...
I ended up placing a white UIView as a background for the date picker, so while the whole view is black, the date picker is white. It actually looks okay, although thankfully I don't have a client who would dictate the design.
One possible argument for a client: the old, pre-iOS7 date picker, also had a predefined non-customisable background.
What you want is possible, but it will be called Custom Date Picker.
Below is the link where you will find what you wanted.
https://www.cocoacontrols.com/controls/simpledatepicker
If you need more, take a loot at below link.
https://www.cocoacontrols.com/search?utf8=%E2%9C%93&q=datepicker
Well I understand your frustration, but iOS7 is under NDA. Usually this kind of views are made using layers, beacuse of sublayerTransform that can make perspective giving the idea of 3D. I would check sublayers if you don't see subviews.
The other poin is that I would not hack too much views/layers hierachy, ios<=6 to ios7 transition shown that hacking isn't a good idea.
UIAppereance protocol is probably the way to go, becauase it makes you change what you can change (without screwing that in the future), maybe you can set a backgroundImage, try to set a 1x1pixel of a blck color png, you should also see an attributed string property, or text property.
I dont think its possible to do that directly by changing the properties of the default UIDatePicker , although you can use custom controls to do it.
This might help,
MWDatePicker - https://github.com/mwermuth/MWDatePicker (Found it in cocoa controls -https://www.cocoacontrols.com/controls/mwdatepicker)
according to the iOS Design Resources:
You cannot customize the appearance of date pickers.
I would suggest one of the below:
Redesign your UI to use the black text
Use a customer datepicker
You should tell your client that his suggestion is against the design principles of iOS 7, which indeed it is. I am not a great fan of iOS 7 myself, but we should all give it a go. Your client should accept the standard iOS 7 UI provisionally, until he is in a position to make an informed judgement. Designing an app based on his initial impressions is a recipe for disaster.

Resources