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)
}
Related
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 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 4 years ago.
Improve this question
In Obj C I created a property
#property(nonatomic) UILabel *subscriptionText;
Then I created a setter method for that property UILabel. like below
-(UILabel *)subscriptionText{
if (!_subscriptionText) {
_subscriptionText = [UILabel new];
_subscriptionText.translatesAutoresizingMaskIntoConstraints = NO;
_subscriptionText.textAlignment = NSTextAlignmentJustified;
}
return _subscriptionText;
}
then In viewdidload I add this view by
[self.view addSubview:self.subscriptionText];
How can I do this same scenario in Swift 4.2.
A lazy initialization is what you need.
lazy var subscriptionText: UILabel = {
let label = UILabel()
label.textAlignment = .justified
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
func viewDidLoad() {
super.viewDidLoad()
view.addSubview(subscriptionLabel)
// Label constraints
}
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.
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 need to perform an effect like this in my app:
How can I do this? I need to animate single letters in the text and not the entire label. I'm using Swift.
EDIT (more details):
I need to animate the letters from right to left using a sort of spring damping (like UIView animation), but I don't know how to achieve this. The most important part of this animation is the first one, where the letters enter from left to right with a variable space between the first ones and the others
A while back I asked a similar question and got this reply from
https://stackoverflow.com/users/4754400/chris-gulley
A very clever piece of code indeed.
class Timer {
typealias TimerFunction = (Int)->Bool
private var handler: TimerFunction
private var i = 0
init(interval: NSTimeInterval, handler: TimerFunction) {
self.handler = handler
NSTimer.scheduledTimerWithTimeInterval(interval, target: self, selector: "timerFired:", userInfo: nil, repeats: true)
}
#objc
private func timerFired(timer:NSTimer) {
if !handler(i++) {
timer.invalidate()
}
}
}
class ViewController: UIViewController {
let text: NSAttributedString = {
let font = UIFont(name: "Georgia", size: 18.0) ?? UIFont.systemFontOfSize(18.0)
return NSAttributedString(string: "A long time ago, in a galaxy far, far away ...", attributes: [NSFontAttributeName: font])
}()
override func viewDidLoad() {
super.viewDidLoad()
let textView = UITextView(frame: CGRect(x: 100, y: 120, width: CGRectGetWidth(self.view.frame), height: CGRectGetWidth(self.view.frame)-20))
self.view.addSubview(textView)
let _ = Timer(interval: 0.1) {i -> Bool in
textView.attributedText = self.text.attributedSubstringFromRange(NSRange(location: 0, length: i+1))
return i + 1 < self.text.string.characters.count
}
}
}
Displaying text one character at a time in swift 2.0