Rozmiar czcionki UILabel?
Nie mogę zmodyfikować rozmiaru czcionki UILabel za pomocą następującego kodu:
itemTitle.font = [UIFont systemFontOfSize:25];
Gdy zwiększam liczbę 25 do czegoś większego, wydaje się, że dodaje się tylko górny margines do etykiety, co w konsekwencji tak bardzo spycha tekst w dół, tak że tekst zostaje odcięty na dole lub całkowicie przepełnia się.
Mam inny UILabel gdzie indziej z systemFontOfSize 25, i jest znacznie mniejszy niż tekst itemTitle. Co się dzieje? Czy 25 nie powinno być wartością absolutną?
Jestem tak zdezorientowany, jak programowo zmienić rozmiar czcionki uilabels.
10 answers
Sprawdź, czy etykiety nie są ustawione na automatyczną zmianę rozmiaru. W IB nazywa się "Autoshrink" i znajduje się tuż obok ustawienia czcionki. Programowo nazywa się adjustsFontSizeToFitWidth
.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-05-07 01:00:33
Zmodyfikowałem UILabel następującym kodem:
label.font=[label.font fontWithSize:25];
Spróbuj tego i zobacz, czy to działa w Twoim przypadku, czy nie???
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-05-07 19:54:07
[label setFont:[UIFont systemFontOfSize:9]];
To mi pasuje.Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-03-18 09:59:38
* * możesz ustawić rozmiar czcionki za pomocą tych właściwości * *
timedisplayLabel= [[UILabel alloc]initWithFrame:CGRectMake(70, 194, 180, 60)];
[timedisplayLabel setTextAlignment:NSTextAlignmentLeft];
[timedisplayLabel setBackgroundColor:[UIColor clearColor]];
[timedisplayLabel setAdjustsFontSizeToFitWidth:YES];
[timedisplayLabel setTextColor:[UIColor blackColor]];
[timedisplayLabel setUserInteractionEnabled:NO];
[timedisplayLabel setFont:[UIFont fontWithName:@"digital-7" size:60]];
timedisplayLabel.layer.shadowColor =[[UIColor whiteColor ]CGColor ];
timedisplayLabel.layer.shadowOffset=(CGSizeMake(0, 0));
timedisplayLabel.layer.shadowOpacity=1;
timedisplayLabel.layer.shadowRadius=3.0;
timedisplayLabel.layer.masksToBounds=NO;
timedisplayLabel.shadowColor=[UIColor darkGrayColor];
timedisplayLabel.shadowOffset=CGSizeMake(0, 2);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-05-25 12:04:44
Dla Swift 3.1 i Swift 4, Jeśli chcesz tylko zmienić rozmiar czcionki dla etykiety:
let myLabel : UILabel = ...
myLabel.font = myLabel.font.withSize(25)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-01-31 06:45:18
Bardzo prosta, ale skuteczna metoda progmatycznego dostosowywania rozmiaru tekstu etykiety: -
label.font=[UIFont fontWithName:@"Chalkduster" size:36];
:-)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-12-10 11:50:03
To mi pomogło:
sequencerPlayLabel.font = [UIFont fontWithName:kTypeFont size:kTypeFontSize];
-rich
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-04-17 14:48:39
To zadziałało dla mnie w
Swift 3
label.font = label.font.fontWithSize(40.0)
Swift 4
label.font = label.font.withSize(40.0)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-10-27 10:14:31
Odpowiedzi powyżej bardzo pomogły.
Oto wersja Swift.
@IBOutlet weak var priceLabel: UILabel!
*.... lines of code later*
self.priceLabel.font = self.priceLabel.font.fontWithSize(22)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-05-12 13:40:12
Spróbuj zmienić rozmiar ramki etykiety wysokość i szerokość, aby tekst nie był cięty.
[label setframe:CGRect(x,y,widht,height)];
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-05-07 19:54:00