NSAttributed Text with a line along with some angle in iOSGetting the range of links in attributed stringMultiple lines of text in UILabelVertically align text to top within a UILabelUITextField text change eventHow to change Status Bar text color in iOSDraw Angled/Rotated MultiLine Text - Core Text + Core GraphicsImage becomes blurry when painting a Image from GraphicContext?How to give multiple colours for a plot with CoreplotiOS Swift Draw line with a brush effectDrawing a 3D cone shape in Swift using a UIBezierPath() and CAShapeLayer()draw a straight line in swift 3 and core graphics

Why do I need two parameters in an HTTP parameter pollution attack?

Skipping over failed imports until they are needed (if ever)

What's the easiest way for a whole party to be able to communicate with a creature that doesn't know Common?

Does the Pi 4 resolve the Ethernet+USB bottleneck issue of past versions?

Why was Mal so quick to drop Bester in favour of Kaylee?

Can the passive "être + verbe" sometimes mean the past?

How exactly is a normal force exerted, at the molecular level?

What's the safest way to inform a new user of their password on my web site?

Can I create a CAA record for all sub-domains

Can I ask to speak to my future colleagues before accepting an offer?

What is the highest number of sneak attacks that a Pure/High Level Rogue (Level 17+) can make in one round?

One folder two different locations on ubuntu 18.04

Should I share with a new service provider a bill from its competitor?

How can my story take place on Earth without referring to our existing cities and countries?

Is it bad to describe a character long after their introduction?

How to fix a dry solder pin in BGA package?

Can Access Fault Exceptions of the MC68040 caused by internal access faults occur in normal situations?

Spicket or spigot?

Why does a brace command group need spaces after the opening brace in POSIX Shell Grammar?

Can two or more lightbeams (from a laser for example) have visible interference when they cross in mid-air?

Do the 26 richest billionaires own as much wealth as the poorest 3.8 billion people?

Are these intended activities legal to do in the USA under the VWP?

Should I report a leak of confidential HR information?

What could a reptilian race tell by candling their eggs?



NSAttributed Text with a line along with some angle in iOS


Getting the range of links in attributed stringMultiple lines of text in UILabelVertically align text to top within a UILabelUITextField text change eventHow to change Status Bar text color in iOSDraw Angled/Rotated MultiLine Text - Core Text + Core GraphicsImage becomes blurry when painting a Image from GraphicContext?How to give multiple colours for a plot with CoreplotiOS Swift Draw line with a brush effectDrawing a 3D cone shape in Swift using a UIBezierPath() and CAShapeLayer()draw a straight line in swift 3 and core graphics






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I want to draw a strike through line in swift 4 as shown in below image.



enter image description here



I have drawn strike through line as shown in below image using followed code.



enter image description here



func strikeThrough(_ color: UIColor) -> NSAttributedString 
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: self)
let textRange = NSRange(location: 0, length: attributeString.length)
attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: 1, range: textRange)
attributeString.addAttribute(NSAttributedString.Key.baselineOffset, value: 0, range: textRange)
attributeString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.lightGray, range: textRange)
attributeString.addAttribute(NSAttributedString.Key.strikethroughColor, value: color, range: textRange)

return attributeString



Any suggestions how do I draw the inclined line over text.
If possible give me a solution using Core Graphics.










share|improve this question






















  • You can use developer.apple.com/documentation/uikit/nslayoutmanager/… and a sample (for underline, but the logic on how to use it is the same: stackoverflow.com/questions/55288142/…), and customize it according to your needs

    – Larme
    Mar 26 at 11:17

















0















I want to draw a strike through line in swift 4 as shown in below image.



enter image description here



I have drawn strike through line as shown in below image using followed code.



enter image description here



func strikeThrough(_ color: UIColor) -> NSAttributedString 
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: self)
let textRange = NSRange(location: 0, length: attributeString.length)
attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: 1, range: textRange)
attributeString.addAttribute(NSAttributedString.Key.baselineOffset, value: 0, range: textRange)
attributeString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.lightGray, range: textRange)
attributeString.addAttribute(NSAttributedString.Key.strikethroughColor, value: color, range: textRange)

return attributeString



Any suggestions how do I draw the inclined line over text.
If possible give me a solution using Core Graphics.










share|improve this question






















  • You can use developer.apple.com/documentation/uikit/nslayoutmanager/… and a sample (for underline, but the logic on how to use it is the same: stackoverflow.com/questions/55288142/…), and customize it according to your needs

    – Larme
    Mar 26 at 11:17













0












0








0








I want to draw a strike through line in swift 4 as shown in below image.



enter image description here



I have drawn strike through line as shown in below image using followed code.



enter image description here



func strikeThrough(_ color: UIColor) -> NSAttributedString 
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: self)
let textRange = NSRange(location: 0, length: attributeString.length)
attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: 1, range: textRange)
attributeString.addAttribute(NSAttributedString.Key.baselineOffset, value: 0, range: textRange)
attributeString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.lightGray, range: textRange)
attributeString.addAttribute(NSAttributedString.Key.strikethroughColor, value: color, range: textRange)

return attributeString



Any suggestions how do I draw the inclined line over text.
If possible give me a solution using Core Graphics.










share|improve this question














I want to draw a strike through line in swift 4 as shown in below image.



enter image description here



I have drawn strike through line as shown in below image using followed code.



enter image description here



func strikeThrough(_ color: UIColor) -> NSAttributedString 
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: self)
let textRange = NSRange(location: 0, length: attributeString.length)
attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: 1, range: textRange)
attributeString.addAttribute(NSAttributedString.Key.baselineOffset, value: 0, range: textRange)
attributeString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.lightGray, range: textRange)
attributeString.addAttribute(NSAttributedString.Key.strikethroughColor, value: color, range: textRange)

return attributeString



Any suggestions how do I draw the inclined line over text.
If possible give me a solution using Core Graphics.







ios swift swift4 line nsattributedstring






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 12:40









Krishnarjun BanothKrishnarjun Banoth

6228 silver badges23 bronze badges




6228 silver badges23 bronze badges












  • You can use developer.apple.com/documentation/uikit/nslayoutmanager/… and a sample (for underline, but the logic on how to use it is the same: stackoverflow.com/questions/55288142/…), and customize it according to your needs

    – Larme
    Mar 26 at 11:17

















  • You can use developer.apple.com/documentation/uikit/nslayoutmanager/… and a sample (for underline, but the logic on how to use it is the same: stackoverflow.com/questions/55288142/…), and customize it according to your needs

    – Larme
    Mar 26 at 11:17
















You can use developer.apple.com/documentation/uikit/nslayoutmanager/… and a sample (for underline, but the logic on how to use it is the same: stackoverflow.com/questions/55288142/…), and customize it according to your needs

– Larme
Mar 26 at 11:17





You can use developer.apple.com/documentation/uikit/nslayoutmanager/… and a sample (for underline, but the logic on how to use it is the same: stackoverflow.com/questions/55288142/…), and customize it according to your needs

– Larme
Mar 26 at 11:17












1 Answer
1






active

oldest

votes


















2














Use UIBezierPath with your UILabel, let's name it label:



 var aPath = UIBezierPath()
aPath.moveToPoint(CGPoint(x: label.frame.origin.x , y:label.frame.origin.y - 10)
aPath.addLineToPoint(CGPoint(x: label.frame.origin.x + label.frame.size.width, y: label.frame.origin.y + label.frame.size.height + 10))
aPath.closePath()
UIColor.redColor().set()
aPath.stroke()


Feel free to play with origins of Points in order to get desired result. Also play with label.layer.addSublayer(aPath)






share|improve this answer

























  • When we use frames it misbehaves when we rotate the screen.

    – Krishnarjun Banoth
    Mar 25 at 12:49











  • The example above gives you an idea. No mention for rotate screen etc :) Anyway adding as sublayer shall fix this issue. See updated response.

    – user3344236
    Mar 25 at 12:51











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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55338027%2fnsattributed-text-with-a-line-along-with-some-angle-in-ios%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Use UIBezierPath with your UILabel, let's name it label:



 var aPath = UIBezierPath()
aPath.moveToPoint(CGPoint(x: label.frame.origin.x , y:label.frame.origin.y - 10)
aPath.addLineToPoint(CGPoint(x: label.frame.origin.x + label.frame.size.width, y: label.frame.origin.y + label.frame.size.height + 10))
aPath.closePath()
UIColor.redColor().set()
aPath.stroke()


Feel free to play with origins of Points in order to get desired result. Also play with label.layer.addSublayer(aPath)






share|improve this answer

























  • When we use frames it misbehaves when we rotate the screen.

    – Krishnarjun Banoth
    Mar 25 at 12:49











  • The example above gives you an idea. No mention for rotate screen etc :) Anyway adding as sublayer shall fix this issue. See updated response.

    – user3344236
    Mar 25 at 12:51
















2














Use UIBezierPath with your UILabel, let's name it label:



 var aPath = UIBezierPath()
aPath.moveToPoint(CGPoint(x: label.frame.origin.x , y:label.frame.origin.y - 10)
aPath.addLineToPoint(CGPoint(x: label.frame.origin.x + label.frame.size.width, y: label.frame.origin.y + label.frame.size.height + 10))
aPath.closePath()
UIColor.redColor().set()
aPath.stroke()


Feel free to play with origins of Points in order to get desired result. Also play with label.layer.addSublayer(aPath)






share|improve this answer

























  • When we use frames it misbehaves when we rotate the screen.

    – Krishnarjun Banoth
    Mar 25 at 12:49











  • The example above gives you an idea. No mention for rotate screen etc :) Anyway adding as sublayer shall fix this issue. See updated response.

    – user3344236
    Mar 25 at 12:51














2












2








2







Use UIBezierPath with your UILabel, let's name it label:



 var aPath = UIBezierPath()
aPath.moveToPoint(CGPoint(x: label.frame.origin.x , y:label.frame.origin.y - 10)
aPath.addLineToPoint(CGPoint(x: label.frame.origin.x + label.frame.size.width, y: label.frame.origin.y + label.frame.size.height + 10))
aPath.closePath()
UIColor.redColor().set()
aPath.stroke()


Feel free to play with origins of Points in order to get desired result. Also play with label.layer.addSublayer(aPath)






share|improve this answer















Use UIBezierPath with your UILabel, let's name it label:



 var aPath = UIBezierPath()
aPath.moveToPoint(CGPoint(x: label.frame.origin.x , y:label.frame.origin.y - 10)
aPath.addLineToPoint(CGPoint(x: label.frame.origin.x + label.frame.size.width, y: label.frame.origin.y + label.frame.size.height + 10))
aPath.closePath()
UIColor.redColor().set()
aPath.stroke()


Feel free to play with origins of Points in order to get desired result. Also play with label.layer.addSublayer(aPath)







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 25 at 12:50

























answered Mar 25 at 12:47









user3344236user3344236

2,9741 gold badge15 silver badges21 bronze badges




2,9741 gold badge15 silver badges21 bronze badges












  • When we use frames it misbehaves when we rotate the screen.

    – Krishnarjun Banoth
    Mar 25 at 12:49











  • The example above gives you an idea. No mention for rotate screen etc :) Anyway adding as sublayer shall fix this issue. See updated response.

    – user3344236
    Mar 25 at 12:51


















  • When we use frames it misbehaves when we rotate the screen.

    – Krishnarjun Banoth
    Mar 25 at 12:49











  • The example above gives you an idea. No mention for rotate screen etc :) Anyway adding as sublayer shall fix this issue. See updated response.

    – user3344236
    Mar 25 at 12:51

















When we use frames it misbehaves when we rotate the screen.

– Krishnarjun Banoth
Mar 25 at 12:49





When we use frames it misbehaves when we rotate the screen.

– Krishnarjun Banoth
Mar 25 at 12:49













The example above gives you an idea. No mention for rotate screen etc :) Anyway adding as sublayer shall fix this issue. See updated response.

– user3344236
Mar 25 at 12:51






The example above gives you an idea. No mention for rotate screen etc :) Anyway adding as sublayer shall fix this issue. See updated response.

– user3344236
Mar 25 at 12:51









Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55338027%2fnsattributed-text-with-a-line-along-with-some-angle-in-ios%23new-answer', 'question_page');

);

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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript