Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
How to render any UIView into a UIImage with Swift in iOS
The code presented below can render any UIView into a UIImage:
let view = UIView()
let imageRenderer = UIGraphicsImageRenderer(size: view.bounds.size)
let renderedImage = imageRenderer.image {ctx in
view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
}
The second part of the task, sharing an image to a social platform, should be posted as a separate question.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am trying to easly store colors, like this:
extension UIColor {
class func color(hexString: UIColor) -> UIColor {
switch color {
case .light :
return UIColor.white
case .dark :
return UIColor.black
}
}
}
So I can do something like cell.myView.backgroundColor = UIColor.dark in a if statement. But the .light and .dark gives me this error:
Pattern cannot match values of type '(UIColor) -> UIColor'
Ant tips?
You could add extensions like this...
extension UIColor {
static let light = UIColor.white
static let dark = UIColor.black
}
And then access them like...
UIColor.light
And
UIColor.dark
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
In stackoverflow is showing only 2 or 3 button ie., through storyboard
Images: https://ibb.co/gSFQX2k
var consolebtn = [UIButton]()
var x = Int()
x = 0
#IBAction func pushButton(sender: UIButton) {
let btn = UIButton()
btn.frame = CGRect(x:x, y:10, width:10, height:10)
btn.setTitle("Button Title",for: .normal)
consolebtn.append(btn)
view.addSubview(btn)
x += 20 // 10 is width & 10 is gap between two button
}
Try going through blog, It uses collection view to solve the problem
https://medium.freecodecamp.org/how-to-make-height-collection-views-dynamic-in-your-ios-apps-7d6ca94d2212
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
In the viewDidLoad() callback below, why does the image?.draw() function not work?
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let image = UIImage(named:"0")
image?.draw(in: CGRect(x: 0, y: 0, width: 100, height: 100))
}
// more code here
}
The method of a UIImage draws a image at a current graphic context. In the method viewDidLoad no a graphic context.
Move the calling of the drawing into draw method of some custom view.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have an anatomic picture and on it, I want to print a image like a dot or something when the user taps on the first image (the body) to point out where does it hurts.
I've already read something on UITapGestureRecognizer, but I don't really understood how it works.
Try this:
override func viewDidLoad() {
super.viewDidLoad()
let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(ViewController.handleTap))
self.imageView.addGestureRecognizer(gestureRecognizer)
}
#objc func handleTap(tap: UITapGestureRecognizer) {
let circle = UIView()
circle.center = tap.locationInView(imageView)
circle.frame.size = CGSize(width: 30, height: 30)
circle.layer.backgroundColor = UIColor.redColor().CGColor
circle.layer.cornerRadius = 15
imageView.addSubview(circle)
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
i want to fill text View in current controller from data existing in popover controller
with out reload data in current controller
can i do it ??
You can use custom delegate method to fill the value.
class PopupviewController {
weak var delegate: filleTextViewDelegate?
func calldelegate () {
delegate?.fillTextview(filledData)
}
}
protocol filleTextViewDelegate : class {
func fillTextview(filledData: String)
}
class CurrentViewController :filleTextViewDelegate {
func fillTextview(filledData: String) {
textView.text = filledData
}
}