9 Kasım 2010, Salı
iOS: UİButton yeniden boyutlandırma metin uzunluğuna göre
Interface builder, holdingKomut=yeniden boyutlandırma bir düğme metni sığdırmak için. Eğer bu düğme görünümü eklendi önce Program aracılığıyla yapmak mümkün olup olmadığını merak ediyordum.
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button.titleLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:12]];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
// I need to know the width needed to accomodate NSStringVariable
[button setTitle:NSStringVariable forState:UIControlStateNormal];
// So that I can set the width property of the button before addSubview
[button setFrame:CGRectMake(10, 0, width, fixedHeight)];
[subNavigation addSubview:button];
CEVAP
9 Kasım 2010, Salı
UİKit, NSString sınıfına eklemeler verilen NSString nesnesi, belirli bir yazı tipi işlenmiş, ele gelecek boyutu vardır.
Doktorlar burada: http://developer.apple.com/library/ios/#documentation/uikit/reference/NSString_UIKit_Additions/Reference/Reference.html
Eğer gidersen Kısacası:
CGSize stringsize = [myString sizeWithFont:[UIFont systemFontOfSize:14]];
//or whatever font you're using
[button setFrame:CGRectMake(10,0,stringsize.width, stringsize.height)];
...yüksekliği için düğmeye Kare olacak ve dize işleme genişliği.
Muhtemelen bu CGSize etrafında tampon boşluk ile deneme yapmak isteyeceksiniz, ama doğru yerde başlayacaksın.
Bunu Paylaş:
Nasıl UİLabel genişlikte metin uzunluğ...
Jquery Değiştirmek Yükseklik Tarayıcı ...
Bir iframe yeniden boyutlandırma içeri...
Metin alanının yeniden boyutlandırma k...
Yeniden boyutlandırma iframe yüksekliğ...