6

我有一个 iphone 应用程序,点击一个按钮,它应该通过在右上角的窗口上显示一些文本和“X”十字符号来打开一个自定义警报视图,就像我们在任何 Web 应用程序的灯箱中一样。

4

5 回答 5

2

这是链接,我认为它可以解决您的问题。

http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-uialertview-custom-graphics/

于 2012-05-28T09:48:41.903 回答
1

如果您想实现自定义警报视图,那么您应该在 ViewController 的帮助下拥有非常有吸引力的警报视图集合的示例代码。试试这个示例代码链接 https://github.com/eigner/CODialog

于 2012-05-28T09:54:17.067 回答
1

这是一个示例如何创建自己的类,其行为类似于警报视图,但您可以放置​​任何您想要的背景/按钮图形:

http://iosdevtricks.blogspot.com/2013/04/creating-custom-alert-view-for-iphone.html

于 2013-05-02T00:06:32.937 回答
0
- (void)willPresentAlertView:(UIAlertView *)alertView; 
- (void)didPresentAlertView:(UIAlertView *)alertView; 

在上述任何消息中,检查子视图及其类并根据需要更改值。请参阅 UIActionSheet 的此示例代码。使用 ns log 搜索所有组件的类并自定义您想要的类。这是 uiactionsheet 代码

for (UIView* view in [actionSheet subviews])
    {
        NSLog(@"%@",[view class]);
        if ([[[view class] description] isEqualToString:@"UIAlertButton"] && [view respondsToSelector:@selector(setAlpha:)])
        {
            [view setAlpha:2.0];
            [view setOpaque:YES];
            if ([view respondsToSelector:@selector(title)])
            {
                NSString* title = [view performSelector:@selector(title)];
                if ([title isEqualToString:@"Cancel"] && [view respondsToSelector:@selector(setBackgroundImage:forState:)] && [view respondsToSelector:@selector(setFrame:)] && [view respondsToSelector:@selector(setFrame:)] && [view respondsToSelector:@selector(setTitleColor:forState:)])
                {

                    [view setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [view setBackgroundImage:[UIImage imageNamed:@"btn-cancel.png"] forState:UIControlStateNormal];
                    [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y+10, view.frame.size.width,view.frame.size.height)];

                }
            }
        }
    }
于 2012-05-28T09:45:49.827 回答
0

在 ReturnAlert.xib 中创建自定义视图

在此处输入图像描述

class ReturnView: UIView, UITextFieldDelegate {


}

class ReturnAlert: UIAlertController {
   var returnView: ReturnView?

   public convenience init(id message: String?) {
      self.init(title: nil, message: "message", preferredStyle: .alert)

      guard let view = UINib(nibName: "ReturnAlert", bundle: Bundle(for: ReturnView.self)).instantiate(withOwner: ReturnView.self, options: nil)[0] as? ReturnView else{
        fatalError("Return view not found")
    }

    self.returnView = view
    view.alert = self
    let parent = self.view.subviews[0].subviews[0]

    for sv in parent.subviews {
        sv.removeFromSuperview()
    }

    view.bounds = CGRect(x: parent.bounds.origin.x, y: parent.bounds.origin.y, width: view.frame.size.width, height: view.frame.size.height)

    parent.addSubview(view)

    let xConstraint = NSLayoutConstraint(item: view, attribute: .centerX, relatedBy: .equal, toItem: parent, attribute: .centerX, multiplier: 1, constant: 0)

    let yConstraint = NSLayoutConstraint(item: view, attribute: .centerY, relatedBy: .equal, toItem: parent, attribute: .centerY, multiplier: 1, constant: 0)

    parent.addConstraint(xConstraint)
    parent.addConstraint(yConstraint)
  }
}
于 2018-05-18T10:32:16.907 回答