【问题标题】:How to Move text on navigation bar如何在导航栏上移动文本
【发布时间】:2012-06-06 09:09:01
【问题描述】:

您好,我必须移动导航栏上的文本。我对滚动文本一无所知。有没有人知道这个,请告诉我。

谢谢

【问题讨论】:

  • 您想在触摸时移动文本还是自动移动文本?

标签: iphone ipad uinavigationbar


【解决方案1】:

我认为您想移动标签文本,就像在 iphone 音乐播放器应用程序中一样。如果是,请执行以下操作。

1`. Download Marquee Label files from this link 'https://github.com/cbpowell/MarqueeLabel'.`


2.   - (void)addMovingLabelText { 
            MarqueeLabel *_lectureName = [[MarqueeLabel alloc] initWithFrame:CGRectMake(0,20,200, 20) duration:5.0 andFadeLength:10.0f];
            [_lectureName setTextAlignment:NSTextAlignmentCenter];
            [_lectureName setBackgroundColor:[UIColor clearColor]];
            [_lectureName setText:@"I am a moving Label in iphone Application"];
            _lectureName.adjustsFontSizeToFitWidth=NO;
            [_lectureName setAnimationCurve:UIViewAnimationOptionCurveEaseIn];
            [self.navigationItem setTitleView:_lectureName];
}

3. call addMovingLabelText from viewDidLoad

【讨论】:

    【解决方案2】:

    将此文件添加到您的项目中并将其导入您的类,然后在您的视图中添加以下命令并加载。我希望您正在为您的应用程序使用基于导航的模板。

    http://blog.stormyprods.com/2009/10/simple-scrolling-uilabel-for-iphone.html

    然后在viewdidload中

    AutoScrollLabel *autoScrollLabel=[[AutoScrollLabel alloc] initWithFrame:CGRectMake(10, 15, 320, 16)];
    autoScrollLabel.text = @"Hi Mom!  How are you?  I really ought to write more often.";
    autoScrollLabel.textColor = [UIColor whiteColor];
    //self.title = @"Resources";
    //self.title = @"%@"autoScrollLabel;
    [self.navigationController.navigationBar addSubview:autoScrollLabel];
    

    【讨论】:

      【解决方案3】:

      好吧,导航栏可以使用您自己的 titleView 进行自定义,因此您需要做的就是创建一个包含滚动文本的视图。因为 SDK 中没有实现这个效果的组件,所以你必须在开源库中寻找或创建自己的。没用过,看看这个UIScrollingLabel

      【讨论】:

        【解决方案4】:

        Swift 5 方法与MarqueeLabel:

            let title = MarqueeLabel(frame: CGRect.zero, duration: 20, fadeLength: 10)
            title.textAlignment = .center
            title.textColor = .white
            title.text = header
        
            navigationController?.navigationBar.topItem?.titleView = title
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-12-06
          • 2011-10-28
          • 2022-01-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多