I set label in UIView with layers colour specific sizes Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Set UIButton title UILabel font size programmaticallyHow to set iPhone UIView z index?UILabel - auto-size label to fit text?iPhone iOS UIFont conversion to CTFontRef causes size misalignmentHow to set cornerRadius for only top-left and top-right corner of a UIView?How to calculate the height of an NSAttributedString with given width in iOS 6Adding a custom UIViewcontroller to subview programmatically but getting an error message “Cannot convert value of type…”Custom transition in Swift 3 does not translate correctlyGLKView.display() method sometimes causes crash. EXC_BAD_ACCESSStrange animation occurs when extending UIView
What is the escape velocity of a neutron particle (not neutron star)
What do you call the main part of a joke?
Dating a Former Employee
Did MS DOS itself ever use blinking text?
Irreducible of finite Krull dimension implies quasi-compact?
Why wasn't DOSKEY integrated with COMMAND.COM?
How can I use the Python library networkx from Mathematica?
Can anything be seen from the center of the Boötes void? How dark would it be?
Circuit to "zoom in" on mV fluctuations of a DC signal?
Do jazz musicians improvise on the parent scale in addition to the chord-scales?
Significance of Cersei's obsession with elephants?
How to show element name in portuguese using elements package?
How would a mousetrap for use in space work?
Wu formula for manifolds with boundary
What does the "x" in "x86" represent?
2001: A Space Odyssey's use of the song "Daisy Bell" (Bicycle Built for Two); life imitates art or vice-versa?
What is the longest distance a player character can jump in one leap?
Where are Serre’s lectures at Collège de France to be found?
Using et al. for a last / senior author rather than for a first author
Can you use the Shield Master feat to shove someone before you make an attack by using a Readied action?
Denied boarding although I have proper visa and documentation. To whom should I make a complaint?
Crossing US/Canada Border for less than 24 hours
Is safe to use va_start macro with this as parameter?
How to react to hostile behavior from a senior developer?
I set label in UIView with layers colour specific sizes
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Set UIButton title UILabel font size programmaticallyHow to set iPhone UIView z index?UILabel - auto-size label to fit text?iPhone iOS UIFont conversion to CTFontRef causes size misalignmentHow to set cornerRadius for only top-left and top-right corner of a UIView?How to calculate the height of an NSAttributedString with given width in iOS 6Adding a custom UIViewcontroller to subview programmatically but getting an error message “Cannot convert value of type…”Custom transition in Swift 3 does not translate correctlyGLKView.display() method sometimes causes crash. EXC_BAD_ACCESSStrange animation occurs when extending UIView
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I set label in UIView with layers colour specific sizes. how can I get border color frame from layer and the code is
func singleMatCalculate()
if ViewController.state.useInches
var height = (frameHeight - actualImageHeight)/2
var width = (frameWidth - actualImageWidth)/2
height /= 72
width /= 72
if !unitState //Fractions
var n = floor(height)
var whole = Int(n)
var fract = rationalApproximationOf(x0: round((height-n) * 100)/100)
if fract.num == 0
SMHeight = "(whole)""
else
SMHeight = "(whole) (fract.num)/(fract.den)""
n = floor(width)
whole = Int(n)
fract = rationalApproximationOf(x0: round((width-n) * 100)/100)
if fract.num == 0
SMWidth = "(whole)""
else
SMWidth = "(whole) (fract.num)/(fract.den)""
else
SMWidth = "(round(width * 100)/100)""
SMHeight = "(round(height * 100)/100)""
else
var height = (frameHeight - actualImageHeight)/2
var width = (frameWidth - actualImageWidth)/2
height /= 28
width /= 28
if !unitState//CentiMeters
SMHeight = "(round(height * 100)/100)cm"
SMWidth = "(round(width * 100)/100)cm"
else
height /= 100
width /= 100
SMHeight = "(round(height * 100)/100)m"
SMWidth = "(round(width * 100)/100)m"
func doubleMatCalculate()
if ViewController.state.useInches
var height = frameHeight - actualImageHeight - (doubleBottom * 2)
var width = frameWidth - actualImageWidth - (doubleBottom * 2)
height /= 144
width /= 144
if unitState //Fractions
DMWidth = "(round(width * 100)/100)""
DMHeight = "(round(height * 100)/100)""
else
var n = floor(height)
var whole = Int(n)
var fract = rationalApproximationOf(x0: round((height-n) * 100)/100)
if fract.num == 0
DMHeight = "(whole)""
else
DMHeight = "(whole) (fract.num)/(fract.den)""
n = floor(width)
whole = Int(n)
fract = rationalApproximationOf(x0: round((width-n) * 100)/100)
if fract.num == 0
DMWidth = "(whole)""
else
DMWidth = "(whole) (fract.num)/(fract.den)""
else
var height = frameHeight - actualImageHeight - (doubleBottom * 2)
var width = frameWidth - actualImageWidth - (doubleBottom * 2)
height /= 28
width /= 28
if !unitState//CentiMeters
DMHeight = "(round(height * 100)/100)cm"
DMWidth = "(round(width * 100)/100)cm"
else
height /= 100
width /= 100
DMHeight = "(round(height * 100)/100)m"
DMWidth = "(round(width * 100)/100)m"
and set border with label
func drawSingle()
if frameRect.height > self.drawArea.frame.height
frameRect.size.height = self.drawArea.frame.height - 50
if frameRect.width > drawArea.frame.width
frameRect.size.width = drawArea.frame.width - 50
frameRect.origin = CGPoint(x: self.view.bounds.midX - (frameRect.width / 2) - 15, y: self.drawArea.bounds.midY - (frameRect.height / 2))
// self.frameRect = rect
if imageRect.height > frameRect.height
imageRect.size.height = frameRect.height - 20
if imageRect.height < 0
imageRect.size.height = 0
if imageRect.width > frameRect.width
imageRect.size.width = frameRect.width - 20
if imageRect.width < 0
imageRect.size.width = 0
imageRect.origin = CGPoint(x: frameRect.midX - (imageRect.width / 2), y: frameRect.midY - (imageRect.height / 2))
singleLayer.path = UIBezierPath.init(rect: frameRect).cgPath
singleLayer.fillColor = colorBot.cgColor
drawArea.layer.addSublayer(singleLayer)
let orig = frameRect.origin
var orig1 = frameRect.origin
var yourLabel: UILabel!
if(self.matState == 1)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig1.y - 40, width: self.view.frame.width/2, height: 30))
else if(self.matState == 0)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig1.y - 35, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig1.y - 28, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(15))
yourLabel.textColor = UIColor.black
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = self.SMW
self.drawArea.addSubview(yourLabel)
if(self.matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 - 27, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
else if(self.matState == 0)
yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 - 17, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 - 15, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(15))
yourLabel.textColor = UIColor.black
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = self.SMH
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
// orig1 = imageRect.origin
// yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig1.y + 20, width: self.view.frame.width/2, height: 30))
// yourLabel.backgroundColor = UIColor.clear
// yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(13))
// yourLabel.textColor = UIColor.white
// yourLabel.textAlignment = NSTextAlignment.center
// yourLabel.text = self.DMW
// self.drawArea.addSubview(yourLabel)
// yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 + 25, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
// yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(13))
// yourLabel.textColor = UIColor.white
// yourLabel.textAlignment = NSTextAlignment.center
// yourLabel.text = self.DMH
// yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
// self.drawArea.addSubview(yourLabel)
//Top
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4 - 15, y: orig.y , width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMHeight
self.drawArea.addSubview(yourLabel)
//Bottom
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig.y - 25 + frameRect.height, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMHeight
self.drawArea.addSubview(yourLabel)
//Left
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 + 15, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Right
yourLabel = UILabel(frame: CGRect(x: frameRect.maxX - self.view.frame.width/4 - 15, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
func drawDouble()
if imageRect.height > frameRect.height
imageRect.size.height = frameRect.height - 20
if imageRect.height < 0
imageRect.size.height = 0
if imageRect.width > frameRect.width
imageRect.size.width = frameRect.width - 20
if imageRect.width < 0
imageRect.size.width = 0
imageRect.origin = CGPoint(x: frameRect.midX - (imageRect.width / 2), y: frameRect.midY - (imageRect.height / 2))
// self.frameRect = rect
doubleLayer.path = UIBezierPath.init(rect: self.imageRect).cgPath
doubleLayer.fillColor = UIColor.clear.cgColor
doubleLayer.lineWidth = 20
doubleLayer.strokeColor = colorMid.cgColor
drawArea.layer.addSublayer(doubleLayer)
//TOP
let orig = frameRect.origin
var yourLabel : UILabel!
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/6 , y: orig.y - 20 , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig.y + 17, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMW)""
yourLabel.backgroundColor = UIColor.clear
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
self.drawArea.addSubview(yourLabel)
//Bottom
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/6, y: orig.y - 20 , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: imageRect.height - 10, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMH)""
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
self.drawArea.addSubview(yourLabel)
// LEft
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 - 10, y: frameRect.midY , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 + 28, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMH)""
//yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: frameRect.midY - 15 , width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Right
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 - 10, y: frameRect.midY , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: imageRect.maxX - self.view.frame.width/4 - 30, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMH)""
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Top
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/6, y: orig.y - 5 , width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig.y - 5 , width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMHeight
self.drawArea.addSubview(yourLabel)
//Bottom
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/6, y: orig.y - 5 , width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig.y - 15 + imageRect.height, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMHeight
self.drawArea.addSubview(yourLabel)
//Left
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: imageRect.midY, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Right
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: imageRect.midY, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: imageRect.maxX - self.view.frame.width/4, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
and image area inner most frame
func drawImage()
var k: Draw!
if ViewController.state.useInches
k = Draw(frame: CGRect(
origin: CGPoint(x: 0, y: 0),
size: CGSize(width: self.frameRect.width - 100, height: self.frameRect.height - 100)))
else
k = Draw(frame: CGRect(
origin: CGPoint(x: 0, y: 0),
size: CGSize(width: self.frameRect.width - 140, height: self.frameRect.height - 108)))
k.backgroundColor = UIColor(hexString: "#EBE2C6")
k.center = CGPoint(x: self.frameRect.midX, y: self.frameRect.midY);
self.drawArea.addSubview(k)
let labeTop = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
labeTop.center = k.center
labeTop.textAlignment = .center
if ViewController.state.useInches
labeTop.text = "(String(format: "%.0f", actualImageWidth / 72))""
else
labeTop.text = "(String(format: "%.0f", actualImageWidth / 72))cm"
labeTop.textColor = updateContrastColor(selectedColor: UIColor(hexString: "#EBE2C6"))
labeTop.frame.origin = k.bounds.origin;
labeTop.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
labeTop.center = CGPoint(x: k.bounds.midX, y: 10);
k.addSubview(labeTop)
let labelLeft = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
labelLeft.textAlignment = .center
if ViewController.state.useInches
labelLeft.text = "(String(format: "%.0f", actualImageHeight / 72))""
else
labelLeft.text = "(String(format: "%.0f", actualImageHeight / 72))cm"
labelLeft.textColor = updateContrastColor(selectedColor: UIColor(hexString: "#EBE2C6"))
labelLeft.frame.origin = k.bounds.origin;
labelLeft.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
labelLeft.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
labelLeft.center = CGPoint(x: 10, y: k.bounds.midY);
k.addSubview(labelLeft)
and the result is this image having labels are not setting please find this solution for what I do for labels....
this is result
and please suggest for drawing frame and layers programmatically
set labels etc thanks
ios swift iphone swift4
add a comment |
I set label in UIView with layers colour specific sizes. how can I get border color frame from layer and the code is
func singleMatCalculate()
if ViewController.state.useInches
var height = (frameHeight - actualImageHeight)/2
var width = (frameWidth - actualImageWidth)/2
height /= 72
width /= 72
if !unitState //Fractions
var n = floor(height)
var whole = Int(n)
var fract = rationalApproximationOf(x0: round((height-n) * 100)/100)
if fract.num == 0
SMHeight = "(whole)""
else
SMHeight = "(whole) (fract.num)/(fract.den)""
n = floor(width)
whole = Int(n)
fract = rationalApproximationOf(x0: round((width-n) * 100)/100)
if fract.num == 0
SMWidth = "(whole)""
else
SMWidth = "(whole) (fract.num)/(fract.den)""
else
SMWidth = "(round(width * 100)/100)""
SMHeight = "(round(height * 100)/100)""
else
var height = (frameHeight - actualImageHeight)/2
var width = (frameWidth - actualImageWidth)/2
height /= 28
width /= 28
if !unitState//CentiMeters
SMHeight = "(round(height * 100)/100)cm"
SMWidth = "(round(width * 100)/100)cm"
else
height /= 100
width /= 100
SMHeight = "(round(height * 100)/100)m"
SMWidth = "(round(width * 100)/100)m"
func doubleMatCalculate()
if ViewController.state.useInches
var height = frameHeight - actualImageHeight - (doubleBottom * 2)
var width = frameWidth - actualImageWidth - (doubleBottom * 2)
height /= 144
width /= 144
if unitState //Fractions
DMWidth = "(round(width * 100)/100)""
DMHeight = "(round(height * 100)/100)""
else
var n = floor(height)
var whole = Int(n)
var fract = rationalApproximationOf(x0: round((height-n) * 100)/100)
if fract.num == 0
DMHeight = "(whole)""
else
DMHeight = "(whole) (fract.num)/(fract.den)""
n = floor(width)
whole = Int(n)
fract = rationalApproximationOf(x0: round((width-n) * 100)/100)
if fract.num == 0
DMWidth = "(whole)""
else
DMWidth = "(whole) (fract.num)/(fract.den)""
else
var height = frameHeight - actualImageHeight - (doubleBottom * 2)
var width = frameWidth - actualImageWidth - (doubleBottom * 2)
height /= 28
width /= 28
if !unitState//CentiMeters
DMHeight = "(round(height * 100)/100)cm"
DMWidth = "(round(width * 100)/100)cm"
else
height /= 100
width /= 100
DMHeight = "(round(height * 100)/100)m"
DMWidth = "(round(width * 100)/100)m"
and set border with label
func drawSingle()
if frameRect.height > self.drawArea.frame.height
frameRect.size.height = self.drawArea.frame.height - 50
if frameRect.width > drawArea.frame.width
frameRect.size.width = drawArea.frame.width - 50
frameRect.origin = CGPoint(x: self.view.bounds.midX - (frameRect.width / 2) - 15, y: self.drawArea.bounds.midY - (frameRect.height / 2))
// self.frameRect = rect
if imageRect.height > frameRect.height
imageRect.size.height = frameRect.height - 20
if imageRect.height < 0
imageRect.size.height = 0
if imageRect.width > frameRect.width
imageRect.size.width = frameRect.width - 20
if imageRect.width < 0
imageRect.size.width = 0
imageRect.origin = CGPoint(x: frameRect.midX - (imageRect.width / 2), y: frameRect.midY - (imageRect.height / 2))
singleLayer.path = UIBezierPath.init(rect: frameRect).cgPath
singleLayer.fillColor = colorBot.cgColor
drawArea.layer.addSublayer(singleLayer)
let orig = frameRect.origin
var orig1 = frameRect.origin
var yourLabel: UILabel!
if(self.matState == 1)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig1.y - 40, width: self.view.frame.width/2, height: 30))
else if(self.matState == 0)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig1.y - 35, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig1.y - 28, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(15))
yourLabel.textColor = UIColor.black
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = self.SMW
self.drawArea.addSubview(yourLabel)
if(self.matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 - 27, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
else if(self.matState == 0)
yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 - 17, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 - 15, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(15))
yourLabel.textColor = UIColor.black
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = self.SMH
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
// orig1 = imageRect.origin
// yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig1.y + 20, width: self.view.frame.width/2, height: 30))
// yourLabel.backgroundColor = UIColor.clear
// yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(13))
// yourLabel.textColor = UIColor.white
// yourLabel.textAlignment = NSTextAlignment.center
// yourLabel.text = self.DMW
// self.drawArea.addSubview(yourLabel)
// yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 + 25, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
// yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(13))
// yourLabel.textColor = UIColor.white
// yourLabel.textAlignment = NSTextAlignment.center
// yourLabel.text = self.DMH
// yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
// self.drawArea.addSubview(yourLabel)
//Top
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4 - 15, y: orig.y , width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMHeight
self.drawArea.addSubview(yourLabel)
//Bottom
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig.y - 25 + frameRect.height, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMHeight
self.drawArea.addSubview(yourLabel)
//Left
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 + 15, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Right
yourLabel = UILabel(frame: CGRect(x: frameRect.maxX - self.view.frame.width/4 - 15, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
func drawDouble()
if imageRect.height > frameRect.height
imageRect.size.height = frameRect.height - 20
if imageRect.height < 0
imageRect.size.height = 0
if imageRect.width > frameRect.width
imageRect.size.width = frameRect.width - 20
if imageRect.width < 0
imageRect.size.width = 0
imageRect.origin = CGPoint(x: frameRect.midX - (imageRect.width / 2), y: frameRect.midY - (imageRect.height / 2))
// self.frameRect = rect
doubleLayer.path = UIBezierPath.init(rect: self.imageRect).cgPath
doubleLayer.fillColor = UIColor.clear.cgColor
doubleLayer.lineWidth = 20
doubleLayer.strokeColor = colorMid.cgColor
drawArea.layer.addSublayer(doubleLayer)
//TOP
let orig = frameRect.origin
var yourLabel : UILabel!
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/6 , y: orig.y - 20 , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig.y + 17, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMW)""
yourLabel.backgroundColor = UIColor.clear
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
self.drawArea.addSubview(yourLabel)
//Bottom
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/6, y: orig.y - 20 , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: imageRect.height - 10, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMH)""
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
self.drawArea.addSubview(yourLabel)
// LEft
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 - 10, y: frameRect.midY , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 + 28, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMH)""
//yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: frameRect.midY - 15 , width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Right
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 - 10, y: frameRect.midY , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: imageRect.maxX - self.view.frame.width/4 - 30, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMH)""
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Top
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/6, y: orig.y - 5 , width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig.y - 5 , width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMHeight
self.drawArea.addSubview(yourLabel)
//Bottom
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/6, y: orig.y - 5 , width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig.y - 15 + imageRect.height, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMHeight
self.drawArea.addSubview(yourLabel)
//Left
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: imageRect.midY, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Right
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: imageRect.midY, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: imageRect.maxX - self.view.frame.width/4, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
and image area inner most frame
func drawImage()
var k: Draw!
if ViewController.state.useInches
k = Draw(frame: CGRect(
origin: CGPoint(x: 0, y: 0),
size: CGSize(width: self.frameRect.width - 100, height: self.frameRect.height - 100)))
else
k = Draw(frame: CGRect(
origin: CGPoint(x: 0, y: 0),
size: CGSize(width: self.frameRect.width - 140, height: self.frameRect.height - 108)))
k.backgroundColor = UIColor(hexString: "#EBE2C6")
k.center = CGPoint(x: self.frameRect.midX, y: self.frameRect.midY);
self.drawArea.addSubview(k)
let labeTop = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
labeTop.center = k.center
labeTop.textAlignment = .center
if ViewController.state.useInches
labeTop.text = "(String(format: "%.0f", actualImageWidth / 72))""
else
labeTop.text = "(String(format: "%.0f", actualImageWidth / 72))cm"
labeTop.textColor = updateContrastColor(selectedColor: UIColor(hexString: "#EBE2C6"))
labeTop.frame.origin = k.bounds.origin;
labeTop.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
labeTop.center = CGPoint(x: k.bounds.midX, y: 10);
k.addSubview(labeTop)
let labelLeft = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
labelLeft.textAlignment = .center
if ViewController.state.useInches
labelLeft.text = "(String(format: "%.0f", actualImageHeight / 72))""
else
labelLeft.text = "(String(format: "%.0f", actualImageHeight / 72))cm"
labelLeft.textColor = updateContrastColor(selectedColor: UIColor(hexString: "#EBE2C6"))
labelLeft.frame.origin = k.bounds.origin;
labelLeft.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
labelLeft.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
labelLeft.center = CGPoint(x: 10, y: k.bounds.midY);
k.addSubview(labelLeft)
and the result is this image having labels are not setting please find this solution for what I do for labels....
this is result
and please suggest for drawing frame and layers programmatically
set labels etc thanks
ios swift iphone swift4
It's really not clear what you are asking, or what you're having trouble with. Please see How to Ask.
– DonMag
Mar 22 at 12:56
in screen shot we adding a black layers in UIView and I want to get these layers frame
– Ali John
Mar 25 at 8:24
add a comment |
I set label in UIView with layers colour specific sizes. how can I get border color frame from layer and the code is
func singleMatCalculate()
if ViewController.state.useInches
var height = (frameHeight - actualImageHeight)/2
var width = (frameWidth - actualImageWidth)/2
height /= 72
width /= 72
if !unitState //Fractions
var n = floor(height)
var whole = Int(n)
var fract = rationalApproximationOf(x0: round((height-n) * 100)/100)
if fract.num == 0
SMHeight = "(whole)""
else
SMHeight = "(whole) (fract.num)/(fract.den)""
n = floor(width)
whole = Int(n)
fract = rationalApproximationOf(x0: round((width-n) * 100)/100)
if fract.num == 0
SMWidth = "(whole)""
else
SMWidth = "(whole) (fract.num)/(fract.den)""
else
SMWidth = "(round(width * 100)/100)""
SMHeight = "(round(height * 100)/100)""
else
var height = (frameHeight - actualImageHeight)/2
var width = (frameWidth - actualImageWidth)/2
height /= 28
width /= 28
if !unitState//CentiMeters
SMHeight = "(round(height * 100)/100)cm"
SMWidth = "(round(width * 100)/100)cm"
else
height /= 100
width /= 100
SMHeight = "(round(height * 100)/100)m"
SMWidth = "(round(width * 100)/100)m"
func doubleMatCalculate()
if ViewController.state.useInches
var height = frameHeight - actualImageHeight - (doubleBottom * 2)
var width = frameWidth - actualImageWidth - (doubleBottom * 2)
height /= 144
width /= 144
if unitState //Fractions
DMWidth = "(round(width * 100)/100)""
DMHeight = "(round(height * 100)/100)""
else
var n = floor(height)
var whole = Int(n)
var fract = rationalApproximationOf(x0: round((height-n) * 100)/100)
if fract.num == 0
DMHeight = "(whole)""
else
DMHeight = "(whole) (fract.num)/(fract.den)""
n = floor(width)
whole = Int(n)
fract = rationalApproximationOf(x0: round((width-n) * 100)/100)
if fract.num == 0
DMWidth = "(whole)""
else
DMWidth = "(whole) (fract.num)/(fract.den)""
else
var height = frameHeight - actualImageHeight - (doubleBottom * 2)
var width = frameWidth - actualImageWidth - (doubleBottom * 2)
height /= 28
width /= 28
if !unitState//CentiMeters
DMHeight = "(round(height * 100)/100)cm"
DMWidth = "(round(width * 100)/100)cm"
else
height /= 100
width /= 100
DMHeight = "(round(height * 100)/100)m"
DMWidth = "(round(width * 100)/100)m"
and set border with label
func drawSingle()
if frameRect.height > self.drawArea.frame.height
frameRect.size.height = self.drawArea.frame.height - 50
if frameRect.width > drawArea.frame.width
frameRect.size.width = drawArea.frame.width - 50
frameRect.origin = CGPoint(x: self.view.bounds.midX - (frameRect.width / 2) - 15, y: self.drawArea.bounds.midY - (frameRect.height / 2))
// self.frameRect = rect
if imageRect.height > frameRect.height
imageRect.size.height = frameRect.height - 20
if imageRect.height < 0
imageRect.size.height = 0
if imageRect.width > frameRect.width
imageRect.size.width = frameRect.width - 20
if imageRect.width < 0
imageRect.size.width = 0
imageRect.origin = CGPoint(x: frameRect.midX - (imageRect.width / 2), y: frameRect.midY - (imageRect.height / 2))
singleLayer.path = UIBezierPath.init(rect: frameRect).cgPath
singleLayer.fillColor = colorBot.cgColor
drawArea.layer.addSublayer(singleLayer)
let orig = frameRect.origin
var orig1 = frameRect.origin
var yourLabel: UILabel!
if(self.matState == 1)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig1.y - 40, width: self.view.frame.width/2, height: 30))
else if(self.matState == 0)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig1.y - 35, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig1.y - 28, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(15))
yourLabel.textColor = UIColor.black
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = self.SMW
self.drawArea.addSubview(yourLabel)
if(self.matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 - 27, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
else if(self.matState == 0)
yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 - 17, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 - 15, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(15))
yourLabel.textColor = UIColor.black
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = self.SMH
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
// orig1 = imageRect.origin
// yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig1.y + 20, width: self.view.frame.width/2, height: 30))
// yourLabel.backgroundColor = UIColor.clear
// yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(13))
// yourLabel.textColor = UIColor.white
// yourLabel.textAlignment = NSTextAlignment.center
// yourLabel.text = self.DMW
// self.drawArea.addSubview(yourLabel)
// yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 + 25, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
// yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(13))
// yourLabel.textColor = UIColor.white
// yourLabel.textAlignment = NSTextAlignment.center
// yourLabel.text = self.DMH
// yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
// self.drawArea.addSubview(yourLabel)
//Top
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4 - 15, y: orig.y , width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMHeight
self.drawArea.addSubview(yourLabel)
//Bottom
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig.y - 25 + frameRect.height, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMHeight
self.drawArea.addSubview(yourLabel)
//Left
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 + 15, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Right
yourLabel = UILabel(frame: CGRect(x: frameRect.maxX - self.view.frame.width/4 - 15, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
func drawDouble()
if imageRect.height > frameRect.height
imageRect.size.height = frameRect.height - 20
if imageRect.height < 0
imageRect.size.height = 0
if imageRect.width > frameRect.width
imageRect.size.width = frameRect.width - 20
if imageRect.width < 0
imageRect.size.width = 0
imageRect.origin = CGPoint(x: frameRect.midX - (imageRect.width / 2), y: frameRect.midY - (imageRect.height / 2))
// self.frameRect = rect
doubleLayer.path = UIBezierPath.init(rect: self.imageRect).cgPath
doubleLayer.fillColor = UIColor.clear.cgColor
doubleLayer.lineWidth = 20
doubleLayer.strokeColor = colorMid.cgColor
drawArea.layer.addSublayer(doubleLayer)
//TOP
let orig = frameRect.origin
var yourLabel : UILabel!
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/6 , y: orig.y - 20 , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig.y + 17, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMW)""
yourLabel.backgroundColor = UIColor.clear
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
self.drawArea.addSubview(yourLabel)
//Bottom
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/6, y: orig.y - 20 , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: imageRect.height - 10, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMH)""
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
self.drawArea.addSubview(yourLabel)
// LEft
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 - 10, y: frameRect.midY , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 + 28, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMH)""
//yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: frameRect.midY - 15 , width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Right
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 - 10, y: frameRect.midY , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: imageRect.maxX - self.view.frame.width/4 - 30, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMH)""
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Top
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/6, y: orig.y - 5 , width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig.y - 5 , width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMHeight
self.drawArea.addSubview(yourLabel)
//Bottom
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/6, y: orig.y - 5 , width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig.y - 15 + imageRect.height, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMHeight
self.drawArea.addSubview(yourLabel)
//Left
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: imageRect.midY, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Right
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: imageRect.midY, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: imageRect.maxX - self.view.frame.width/4, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
and image area inner most frame
func drawImage()
var k: Draw!
if ViewController.state.useInches
k = Draw(frame: CGRect(
origin: CGPoint(x: 0, y: 0),
size: CGSize(width: self.frameRect.width - 100, height: self.frameRect.height - 100)))
else
k = Draw(frame: CGRect(
origin: CGPoint(x: 0, y: 0),
size: CGSize(width: self.frameRect.width - 140, height: self.frameRect.height - 108)))
k.backgroundColor = UIColor(hexString: "#EBE2C6")
k.center = CGPoint(x: self.frameRect.midX, y: self.frameRect.midY);
self.drawArea.addSubview(k)
let labeTop = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
labeTop.center = k.center
labeTop.textAlignment = .center
if ViewController.state.useInches
labeTop.text = "(String(format: "%.0f", actualImageWidth / 72))""
else
labeTop.text = "(String(format: "%.0f", actualImageWidth / 72))cm"
labeTop.textColor = updateContrastColor(selectedColor: UIColor(hexString: "#EBE2C6"))
labeTop.frame.origin = k.bounds.origin;
labeTop.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
labeTop.center = CGPoint(x: k.bounds.midX, y: 10);
k.addSubview(labeTop)
let labelLeft = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
labelLeft.textAlignment = .center
if ViewController.state.useInches
labelLeft.text = "(String(format: "%.0f", actualImageHeight / 72))""
else
labelLeft.text = "(String(format: "%.0f", actualImageHeight / 72))cm"
labelLeft.textColor = updateContrastColor(selectedColor: UIColor(hexString: "#EBE2C6"))
labelLeft.frame.origin = k.bounds.origin;
labelLeft.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
labelLeft.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
labelLeft.center = CGPoint(x: 10, y: k.bounds.midY);
k.addSubview(labelLeft)
and the result is this image having labels are not setting please find this solution for what I do for labels....
this is result
and please suggest for drawing frame and layers programmatically
set labels etc thanks
ios swift iphone swift4
I set label in UIView with layers colour specific sizes. how can I get border color frame from layer and the code is
func singleMatCalculate()
if ViewController.state.useInches
var height = (frameHeight - actualImageHeight)/2
var width = (frameWidth - actualImageWidth)/2
height /= 72
width /= 72
if !unitState //Fractions
var n = floor(height)
var whole = Int(n)
var fract = rationalApproximationOf(x0: round((height-n) * 100)/100)
if fract.num == 0
SMHeight = "(whole)""
else
SMHeight = "(whole) (fract.num)/(fract.den)""
n = floor(width)
whole = Int(n)
fract = rationalApproximationOf(x0: round((width-n) * 100)/100)
if fract.num == 0
SMWidth = "(whole)""
else
SMWidth = "(whole) (fract.num)/(fract.den)""
else
SMWidth = "(round(width * 100)/100)""
SMHeight = "(round(height * 100)/100)""
else
var height = (frameHeight - actualImageHeight)/2
var width = (frameWidth - actualImageWidth)/2
height /= 28
width /= 28
if !unitState//CentiMeters
SMHeight = "(round(height * 100)/100)cm"
SMWidth = "(round(width * 100)/100)cm"
else
height /= 100
width /= 100
SMHeight = "(round(height * 100)/100)m"
SMWidth = "(round(width * 100)/100)m"
func doubleMatCalculate()
if ViewController.state.useInches
var height = frameHeight - actualImageHeight - (doubleBottom * 2)
var width = frameWidth - actualImageWidth - (doubleBottom * 2)
height /= 144
width /= 144
if unitState //Fractions
DMWidth = "(round(width * 100)/100)""
DMHeight = "(round(height * 100)/100)""
else
var n = floor(height)
var whole = Int(n)
var fract = rationalApproximationOf(x0: round((height-n) * 100)/100)
if fract.num == 0
DMHeight = "(whole)""
else
DMHeight = "(whole) (fract.num)/(fract.den)""
n = floor(width)
whole = Int(n)
fract = rationalApproximationOf(x0: round((width-n) * 100)/100)
if fract.num == 0
DMWidth = "(whole)""
else
DMWidth = "(whole) (fract.num)/(fract.den)""
else
var height = frameHeight - actualImageHeight - (doubleBottom * 2)
var width = frameWidth - actualImageWidth - (doubleBottom * 2)
height /= 28
width /= 28
if !unitState//CentiMeters
DMHeight = "(round(height * 100)/100)cm"
DMWidth = "(round(width * 100)/100)cm"
else
height /= 100
width /= 100
DMHeight = "(round(height * 100)/100)m"
DMWidth = "(round(width * 100)/100)m"
and set border with label
func drawSingle()
if frameRect.height > self.drawArea.frame.height
frameRect.size.height = self.drawArea.frame.height - 50
if frameRect.width > drawArea.frame.width
frameRect.size.width = drawArea.frame.width - 50
frameRect.origin = CGPoint(x: self.view.bounds.midX - (frameRect.width / 2) - 15, y: self.drawArea.bounds.midY - (frameRect.height / 2))
// self.frameRect = rect
if imageRect.height > frameRect.height
imageRect.size.height = frameRect.height - 20
if imageRect.height < 0
imageRect.size.height = 0
if imageRect.width > frameRect.width
imageRect.size.width = frameRect.width - 20
if imageRect.width < 0
imageRect.size.width = 0
imageRect.origin = CGPoint(x: frameRect.midX - (imageRect.width / 2), y: frameRect.midY - (imageRect.height / 2))
singleLayer.path = UIBezierPath.init(rect: frameRect).cgPath
singleLayer.fillColor = colorBot.cgColor
drawArea.layer.addSublayer(singleLayer)
let orig = frameRect.origin
var orig1 = frameRect.origin
var yourLabel: UILabel!
if(self.matState == 1)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig1.y - 40, width: self.view.frame.width/2, height: 30))
else if(self.matState == 0)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig1.y - 35, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig1.y - 28, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(15))
yourLabel.textColor = UIColor.black
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = self.SMW
self.drawArea.addSubview(yourLabel)
if(self.matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 - 27, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
else if(self.matState == 0)
yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 - 17, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 - 15, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(15))
yourLabel.textColor = UIColor.black
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = self.SMH
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
// orig1 = imageRect.origin
// yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig1.y + 20, width: self.view.frame.width/2, height: 30))
// yourLabel.backgroundColor = UIColor.clear
// yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(13))
// yourLabel.textColor = UIColor.white
// yourLabel.textAlignment = NSTextAlignment.center
// yourLabel.text = self.DMW
// self.drawArea.addSubview(yourLabel)
// yourLabel = UILabel(frame: CGRect(x: orig1.x - self.view.frame.width/4 + 25, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
// yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(13))
// yourLabel.textColor = UIColor.white
// yourLabel.textAlignment = NSTextAlignment.center
// yourLabel.text = self.DMH
// yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
// self.drawArea.addSubview(yourLabel)
//Top
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4 - 15, y: orig.y , width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMHeight
self.drawArea.addSubview(yourLabel)
//Bottom
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/4, y: orig.y - 25 + frameRect.height, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMHeight
self.drawArea.addSubview(yourLabel)
//Left
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 + 15, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Right
yourLabel = UILabel(frame: CGRect(x: frameRect.maxX - self.view.frame.width/4 - 15, y: frameRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorBot)
yourLabel.font = UIFont(name: "Exo", size: CGFloat(15))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = SMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
func drawDouble()
if imageRect.height > frameRect.height
imageRect.size.height = frameRect.height - 20
if imageRect.height < 0
imageRect.size.height = 0
if imageRect.width > frameRect.width
imageRect.size.width = frameRect.width - 20
if imageRect.width < 0
imageRect.size.width = 0
imageRect.origin = CGPoint(x: frameRect.midX - (imageRect.width / 2), y: frameRect.midY - (imageRect.height / 2))
// self.frameRect = rect
doubleLayer.path = UIBezierPath.init(rect: self.imageRect).cgPath
doubleLayer.fillColor = UIColor.clear.cgColor
doubleLayer.lineWidth = 20
doubleLayer.strokeColor = colorMid.cgColor
drawArea.layer.addSublayer(doubleLayer)
//TOP
let orig = frameRect.origin
var yourLabel : UILabel!
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/6 , y: orig.y - 20 , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig.y + 17, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMW)""
yourLabel.backgroundColor = UIColor.clear
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
self.drawArea.addSubview(yourLabel)
//Bottom
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: frameRect.midX - self.view.frame.width/6, y: orig.y - 20 , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: imageRect.height - 10, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMH)""
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
self.drawArea.addSubview(yourLabel)
// LEft
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 - 10, y: frameRect.midY , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 + 28, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMH)""
//yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: frameRect.midY - 15 , width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Right
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4 - 10, y: frameRect.midY , width: self.view.frame.width/2, height: 30))
var rational = rationalApproximationOf(x0: doubleBottom/72)
yourLabel.text = String("(rational.num)/(rational.den)"")
else
yourLabel = UILabel(frame: CGRect(x: imageRect.maxX - self.view.frame.width/4 - 30, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.text = "(self.DMH)""
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
//yourLabel.textColor = UIColor.white
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Top
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/6, y: orig.y - 5 , width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig.y - 5 , width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMHeight
self.drawArea.addSubview(yourLabel)
//Bottom
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/6, y: orig.y - 5 , width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: imageRect.midX - self.view.frame.width/4, y: orig.y - 15 + imageRect.height, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMHeight
self.drawArea.addSubview(yourLabel)
//Left
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: imageRect.midY, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
//Right
if(matState == 1)
yourLabel = UILabel(frame: CGRect(x: orig.x - self.view.frame.width/4, y: imageRect.midY, width: self.view.frame.width/2, height: 30))
else
yourLabel = UILabel(frame: CGRect(x: imageRect.maxX - self.view.frame.width/4, y: imageRect.midY - 15, width: self.view.frame.width/2, height: 30))
yourLabel.backgroundColor = UIColor.clear
yourLabel.textColor = updateContrastColor(selectedColor: colorMid)
//yourLabel.textColor = UIColor.green
yourLabel.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
yourLabel.textAlignment = NSTextAlignment.center
yourLabel.text = DMWidth
yourLabel.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
self.drawArea.addSubview(yourLabel)
and image area inner most frame
func drawImage()
var k: Draw!
if ViewController.state.useInches
k = Draw(frame: CGRect(
origin: CGPoint(x: 0, y: 0),
size: CGSize(width: self.frameRect.width - 100, height: self.frameRect.height - 100)))
else
k = Draw(frame: CGRect(
origin: CGPoint(x: 0, y: 0),
size: CGSize(width: self.frameRect.width - 140, height: self.frameRect.height - 108)))
k.backgroundColor = UIColor(hexString: "#EBE2C6")
k.center = CGPoint(x: self.frameRect.midX, y: self.frameRect.midY);
self.drawArea.addSubview(k)
let labeTop = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
labeTop.center = k.center
labeTop.textAlignment = .center
if ViewController.state.useInches
labeTop.text = "(String(format: "%.0f", actualImageWidth / 72))""
else
labeTop.text = "(String(format: "%.0f", actualImageWidth / 72))cm"
labeTop.textColor = updateContrastColor(selectedColor: UIColor(hexString: "#EBE2C6"))
labeTop.frame.origin = k.bounds.origin;
labeTop.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
labeTop.center = CGPoint(x: k.bounds.midX, y: 10);
k.addSubview(labeTop)
let labelLeft = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
labelLeft.textAlignment = .center
if ViewController.state.useInches
labelLeft.text = "(String(format: "%.0f", actualImageHeight / 72))""
else
labelLeft.text = "(String(format: "%.0f", actualImageHeight / 72))cm"
labelLeft.textColor = updateContrastColor(selectedColor: UIColor(hexString: "#EBE2C6"))
labelLeft.frame.origin = k.bounds.origin;
labelLeft.font = UIFont(name: "Exo-Bold", size: CGFloat(10))
labelLeft.transform = CGAffineTransform(rotationAngle: -1 * (CGFloat.pi/2))
labelLeft.center = CGPoint(x: 10, y: k.bounds.midY);
k.addSubview(labelLeft)
and the result is this image having labels are not setting please find this solution for what I do for labels....
this is result
and please suggest for drawing frame and layers programmatically
set labels etc thanks
ios swift iphone swift4
ios swift iphone swift4
edited Mar 22 at 9:43
vadian
157k17168193
157k17168193
asked Mar 22 at 9:39
Ali JohnAli John
22
22
It's really not clear what you are asking, or what you're having trouble with. Please see How to Ask.
– DonMag
Mar 22 at 12:56
in screen shot we adding a black layers in UIView and I want to get these layers frame
– Ali John
Mar 25 at 8:24
add a comment |
It's really not clear what you are asking, or what you're having trouble with. Please see How to Ask.
– DonMag
Mar 22 at 12:56
in screen shot we adding a black layers in UIView and I want to get these layers frame
– Ali John
Mar 25 at 8:24
It's really not clear what you are asking, or what you're having trouble with. Please see How to Ask.
– DonMag
Mar 22 at 12:56
It's really not clear what you are asking, or what you're having trouble with. Please see How to Ask.
– DonMag
Mar 22 at 12:56
in screen shot we adding a black layers in UIView and I want to get these layers frame
– Ali John
Mar 25 at 8:24
in screen shot we adding a black layers in UIView and I want to get these layers frame
– Ali John
Mar 25 at 8:24
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296729%2fi-set-label-in-uiview-with-layers-colour-specific-sizes%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296729%2fi-set-label-in-uiview-with-layers-colour-specific-sizes%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It's really not clear what you are asking, or what you're having trouble with. Please see How to Ask.
– DonMag
Mar 22 at 12:56
in screen shot we adding a black layers in UIView and I want to get these layers frame
– Ali John
Mar 25 at 8:24