how to obtain the lineHeight property in UITextView

I am trying to calculate the line height in UITextView for my app. I have used the

sizeWithFont:constrainedToSize:lineBreakMode:
method, but it seems to give me the height of all lines in the textview. I heard about the Three20 library, but I am not sure how to utilize it. Can someone provide guidance on this?

Is the Three20 library safe to use? I have come across articles mentioning apps being rejected by iPhone due to its usage.

Your assistance is greatly appreciated. Thank you!

Best regards,

-risma-

Answer №1

Finally...

After receiving Prasanna's answer, I have found my solution. Thank you for your input, Prasanna! I have come up with many ideas based on it. In this particular scenario, instead of using the size from the frame, I opted to utilize the contentSize from the textview. Here is the code snippet I created:

NSString *head = [textView.text substringToIndex:textView.selectedRange.location];

//--get the size of this part--
CGSize initialSize = [head sizeWithFont:textView.font constrainedToSize:textView.contentSize]; 

NSUInteger startOfLine = [head length];


NSRange delimiter = [head rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:textView.text] options:NSBackwardsSearch range:NSMakeRange(0, startOfLine)];


//--substring the part after cursor position--
NSString *tail = [head substringFromIndex:delimiter.location];

//--gets the size of this part--
CGSize lineSize = [tail sizeWithFont:textView.font forWidth:textView.contentSize.width lineBreakMode:UILineBreakModeWordWrap];

This solution works well for me, and perhaps it could be useful to you too, Prasanna.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting problem with nested image carousel in Bootstrap modal

I am working on implementing a modal for displaying an image gallery. The initial modal showcases thumbnails, and upon clicking a thumbnail, a secondary modal should open on top with larger images displayed in a carousel. The issue I'm facing is that ...

Issue with DIV element wrongly breaking on iPhone Safari and Chrome - fix verified

I am currently working on a basic web application, but I'm facing an issue that's proving to be quite puzzling. When viewed on Desktop Chrome with the display set to iPhone 12 Pro (although I have a 13 Pro), everything looks perfectly aligned in ...

Tips for passing down CSS styles through Less stylesheets

In an effort to create a legend below a <table> that matches the colors defined in Bootstrap stylesheets, I am struggling with the following: .table > thead > tr > td.warning, .table > tbody > tr > td.warning, .table > tfoot ...

Ways to initiate animation using CSS when the page loads

Is there a way to initialize the counter on page load? Even though I was successful in making it start on hover, I couldn't figure out how to make it work when the page loads. Here is the JavaScript code: var root = document.querySelector(':root ...

Tips for minimizing the gaps between cards in Bootstrap 5 through CSS

What is the best way to adjust card spacing in Bootstrap 5 using CSS? Here is the HTML code for the cards section: <section id="services"> <div class="container"> <div class="row text-center"> <d ...

A guide to utilizing CSS to showcase the content of all four div elements in HTML body simultaneously

Is there a way to use CSS to display the content of all 4 divs in the same place on the HTML body, based on the URL clicked? Only one div should be displayed at a time in the center of the page. For example, if URL #1 is clicked, it should show the conten ...

Tips for keeping the main section from scrolling while scrolling through the side navigation

Within my Angular application, I have implemented a sidenav and a main section. My desired behavior is to prevent any scrolling in the main section while I am scrolling in the sidenav, similar to the functionality seen on the Angular Material Design docume ...

The card-img-overlay in Bootstrap 5 seamlessly integrates into the following div container

Currently, I am in the process of creating a painting website layout for my CS50 homepage. However, there seems to be an issue with the background-color: rgba(0,0,0,0.7); not aligning correctly with the images within the card-group. <div class="car ...

Obtaining specific Google Image Search results depending on certain criteria

I am working on a project to create a web application that can suggest outfits based on the weather of a specific location. Here is where I am at with the project so far: https://codepen.io/anchpags/pen/bMpjxX <html> <head> <link rel=" ...

How can I use jQuery to set a background image and position on a website?

I am trying to incorporate a background image fade effect along with the color fade in and out when hovering over a link using my current code. However, I am unsure of how to set the background image and position within the code. $(document).ready(funct ...

- Customizing the width of each dropdown level in a unique way

Working on a customized menu design that you can view live at: Focusing on the third level menu, I encountered an issue where all menus have the same width due to sharing the dropdown-menu class. While I understand the root cause of the problem, I am unsu ...

Ways to access the preceding DIV element closest to the current one

Hovering over the text My will cause the image myicon.png to fade out and back in: <div class="mmItemStyleChild"> <img src="theImages/myicon.png" class="mIcon vertAlign mmm1" id="mMW1" /> <img src="theImages/emptyImg.png" class="mSpacer ...

Expanding the Bootstrap panel to a specific size with a scrollable panel-body

Is there a way to create a panel in bootstrap with specific maximum and minimum lengths? My goal is to set a fixed length for the panel body and enable a scroll bar if the text overflows that length. I've been attempting to increase the length of the ...

A dynamic 3-column layout featuring a fluid design, with the middle div expanding based on the

Sorry for the vague title, I'm struggling to explain my issue clearly, so let me elaborate. I am using flexbox to create a 3-column layout and want the middle column to expand when either or both of the side panels are collapsed. Here is a screenshot ...

What is the process for adjusting the attribute of a subitem utilized by the `use` element?

Currently, I am studying SVG and have a question about changing the circle fill value of the second use element. Here is what I have tried: * { stroke: brown; stroke-width: 1; fill: none; } .canvas{ border-color: green; border-style: solid; border-widt ...

The candy stripes on a loading bar zebra assist in creating a unique and

I'm in the process of creating my portfolio and I'd like to incorporate unique animated loading bars, such as vertical or horizontal candy stripes, to showcase my coding skills. Can anyone suggest a specific programming language or tool that woul ...

I am encountering issues with setting a background image in Bootstrap 3.1.1 while trying to achieve a par

I'm struggling to add a background image to my bootstrap site. I'm attempting to create a parallax site using stellar.js, and while the site is functional with text on each slide and correct scrolling links, the images just won't load. Despi ...

Is there a way to disable certain CSS features in Chrome, like CSS grid, for testing purposes?

I'm exploring alternative layouts for my app in case CSS grid is not supported. Is there a way to disable features like CSS grid in Chrome or Canary? ...

My div is becoming overly wide due to padding and margin issues

Looking at this div: <!------ CODE SNIPPET ------> <div id="content"> <div class="top"> I am cool<br /> I am cool<br /> I am cool<br /> I am cool<br /> </div> </div> <!------ /CODE SNIPP ...

What could be causing my Time Picker MUI to malfunction in my React project?

I am currently working on a React and Rails project where I am attempting to style my React components. However, I have encountered an issue with the MUI component Time and Date picker. Whenever I try to implement the time picker, I get a strange error reg ...