0

キーボードが表示されたときに、inputAccessoryView 内の UILabel で AutoScrollLabel を使用する方法。IBメソッドを使用してコードに接続していないため、使用に問題があるようです。私はこれをプログラム的に行います。AutoScrollView の .h ファイルをインポートしましたが、エラーが発生します。 ここで AutoScrollLabel を見つけます

これは、inputAccessoryView の私のコードです。

- (void)viewDidLoad
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake
(0, 0, 320, 23)];
label.backgroundColor = [UIColor clearColor];
label.shadowOffset = CGSizeMake(0, 1);
label.text = @"24 Hour time format only!";
label.font = [UIFont systemFontOfSize:17.0];
[label setTextColor:[UIColor whiteColor]];

UIBarButtonItem *text2 = [[UIBarButtonItem alloc] initWithCustomView:label];

UIToolbar* numberToolbar = [[UIToolbar alloc]init];
numberToolbar.barStyle = UIBarStyleBlackOpaque;
numberToolbar.items = [NSArray arrayWithObjects:text2, nil];
[numberToolbar sizeToFit];
4

2 に答える 2

0

私の例では、xib でラベルを作成し、表示されたらそれをキーボード acc に追加します。

次のようにラベルを宣言します

@property (strong, nonatomic) IBOutlet CBAutoScrollLabel *autoScrollLabel;

viewDidLoad

self.autoScrollLabel.text = @"This text may be clipped, but now it will be scrolled. This text will be scrolled even after device rotation.";
    self.autoScrollLabel.textColor = [UIColor blueColor];
    self.autoScrollLabel.labelSpacing = 35; // distance between start and end labels
    self.autoScrollLabel.pauseInterval = 1.7; // seconds of pause before scrolling starts again
    self.autoScrollLabel.scrollSpeed = 30; // pixels per second
    self.autoScrollLabel.textAlignment = NSTextAlignmentCenter; // centers text when no auto-scrolling is applied
    self.autoScrollLabel.fadeLength = 12.f;
    self.autoScrollLabel.scrollDirection = CBAutoScrollDirectionLeft;
    [self.autoScrollLabel observeApplicationNotifications];

次に、以下のようにテキストフィールドデリゲートメソッドにコードを追加textFieldDidBeginEditing:します

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    textField.inputAccessoryView = self.autoScrollLabel;
}

そして最後に、以下のようにコードを追加textFieldDidBeginEditing:します

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    textField.inputAccessoryView = nil;
}
于 2013-12-27T05:53:24.493 に答える