iCulture forum | iPhone, iPad,  iPod touch, Apple TV en iOS

iCulture forum | iPhone, iPad, iPod touch, Apple TV en iOS (https://forum.iculture.nl/)
-   Ontwikkelen voor iOS (https://forum.iculture.nl/f133/development/f58/ontwikkelen-voor-ios/)
-   -   UILabel height (https://forum.iculture.nl/f133/development/f58/ontwikkelen-voor-ios/68451-uilabel-height.html)

yozefff 14-08-10 21:58

UILabel height
 
Okey .. zal vast iets kleins zijn, maar lukt mij niet om te vinden ;-)

Heb in de IB een UILabel opgezet en in mijn code:

Code:

// setup label
sv.text =  @"When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.";
sv.lineBreakMode = UILineBreakModeWordWrap;
sv.numberOfLines = 0;
[sv sizeToFit];

maar nu wil ik weten wat de hoogte van sv is.

had al iets van sv.frame.size.height geprobeerd .. maar helaas :(

JNikoy 14-08-10 22:30

Lees je de hoogte uit als float of integer? Afhankelijk van hoe je de height property gebruikt kan deze bij een integer nl. een 0 terug geven. Als je de waarde als float uitleest zou dit in principe gewoon moeten werken. Als je in je code eens dit plaatst:

NSLog([NSString stringWithFormat:@"Hoogte: %f", sv.frame.size.height]);

Geeft 'ie dan wel de juiste hoogte terug?

yozefff 14-08-10 22:46

Citaat:

Oorspronkelijk geplaatst door JNikoy (Bericht 531282)
Lees je de hoogte uit als float of integer? Afhankelijk van hoe je de height property gebruikt kan deze bij een integer nl. een 0 terug geven. Als je de waarde als float uitleest zou dit in principe gewoon moeten werken. Als je in je code eens dit plaatst:

NSLog([NSString stringWithFormat:@"Hoogte: %f", sv.frame.size.height]);

Geeft 'ie dan wel de juiste hoogte terug?

WOW ... ja man .. dat was het gewoon ... inderdaad .. ik deed wel nslog maar dan kreeg ik gewoon null terug (NSLog(@"%@",sv.frame.size.height))

Top man .. was al een halve dag aan het zoeken ;-)

JNikoy 14-08-10 22:57

%@ is de formatter voor een object (vaak strings). Tip: Als je na een . op ESC drukt, zie je in het lijstje de typen erbij staan (in dit geval een vierkantje met een f erin). Mocht je het nog eens nodig hebben staat op String Programming Guide: String Format Specifiers overigens een lijstje met alle formatters.

yozefff 15-08-10 12:49

ok nu heb ik een ander probleem .. de reden dat ik de hoogte wou weten is dat de label in een scrollview zit en wil de contentsize zelfde hoogte maken alse de label. Straks komen er meerdere componenten erbij en de bedoeling is dat de contentsize telkens groter wordt.

Probleem is nu .. als ik de height gebruik van mijn voorbeeld hierboven krijg ik 506.000 ... als ik die waarde gebruik voor mijn scrollview:

Code:

scrollView.contentSize                        = CGSizeMake(scrollView.frame.size.width, sv.frame.size.height);
dan krijg kan ik niet nar beneden scrollen. Dus volgens mij is de contentsize te klein. Nu dacht ik , misschien komt het door de float, dus ik voerde 560 hard in

Code:

scrollView.contentSize                        =  CGSizeMake(scrollView.frame.size.width, 560);
maar krijg zelfde resultaat ...

na wat testen kwam ik op ong 580 ... Wat mis ik hier?

yozefff 16-08-10 01:32

hmm denk dat ik het al heb ...

wat ik nog vergat te vertellen ... de view met daarin de scrollview + label zit nog in een view ;-) ... eigenlijk is het

[UINavigationBar]
- UISegmentedControl
- UIView
-- UIScrollView
--- UILabel

ik pakte nu de origin.y van de UIView en dat is 76 ... en als ik die toevoeg bij die contentsize dan klopt het wel ;-) ..


Alle tijden zijn GMT +2. Het is nu 15:01.