代码之家  ›  专栏  ›  技术社区  ›  TheLearner

如何更改Popover的外观

  •  2
  • TheLearner  · 技术社区  · 14 年前

    有没有什么办法可以改变弹出窗口的外观?我想把边界改得更浅,也许比黑更透明

    2 回复  |  直到 14 年前
        1
  •  0
  •   Chris Kooken    14 年前

    我不这么认为……我一直在搜索互联网试图解决同样的问题。现在看来,黑色是唯一的选择。

        2
  •  1
  •   KreÅ¡imir Prcela    14 年前

    下面是如何显示简单弹出窗口的示例,这些弹出窗口将在几秒钟后显示动画并消失。头文件:

    @interface ViewPopup : UIView 
    {
      IBOutlet UILabel *m_lblMessage;
    }
    @property (nonatomic, retain) UILabel *m_lblMessage;
    - (void) showFromView: (UIView*)viewParent;
    

    实施部分:

    @implementation ViewPopup
    @synthesize m_lblMessage;
    - (void) showFromView: (UIView*)viewParent
    {
      [viewParent addSubview:self];
      [self setCenter: CGPointMake(viewParent.frame.size.width/2, -self.frame.size.height/2)];
      [UIView beginAnimations: @"ShowPopup" context: nil];
      [UIView setAnimationDuration: 0.5];
      [UIView setAnimationDelegate: self];
      [UIView setAnimationDidStopSelector: @selector(onAppeared)];
      self.transform = CGAffineTransformMakeTranslation(0, self.frame.size.height+40);
      [UIView commitAnimations];
    }
    - (void) onAppeared
    {
      [self performSelector: @selector(hide) withObject: nil afterDelay: 3];
    }
    - (void) hide
    {
      [UIView beginAnimations: @"HidePopup" context: nil];
      [UIView setAnimationDuration: 1];
      [UIView setAnimationDelegate: self];
      [UIView setAnimationDidStopSelector: @selector(removeFromSuperview)];
      self.transform = CGAffineTransformIdentity;
      [UIView commitAnimations];
    }
    - (void)dealloc 
    {
      [m_lblMessage release];
      [super dealloc];
    }
    

    从任何视图和代码中的任何位置调用:

    ViewPopup *viewPopup = (ViewPopup*)[[NSBundle mainBundle] getViewFromNib: @"ViewPopup" class: [ViewPopup class] owner: nil];
    viewPopup.m_lblMessage.text = @"Hello";
    [viewPopup showFromView: someView];
    

    请注意,弹出图形是从viewpopup.xib文件加载的。它只有一些图形和文本标签。