【问题标题】:Adding Tag View to Xamarin iOS Application将标记视图添加到 Xamarin iOS 应用程序
【发布时间】:2018-07-25 13:22:53
【问题描述】:

如何在附加图像中生成标签气泡。我已经使用 TagView 组件为 android 完成了此操作,但不确定如何为 Xamarin iOS 执行此操作?我可以参考任何组件吗?

【问题讨论】:

标签: ios xamarin xamarin.ios


【解决方案1】:

您必须自己编写这个自定义组件。 我建议在 XIB/Storyboard 中设计这个并将它们放在运行时。

以编程方式创建这样一个子视图的非常粗略的想法可能类似于

    var myView = new UIView(frame: new CoreGraphics.CGRect(10, 10, 120, 40));
    myView.BackgroundColor = UIColor.Blue;

    myView.Layer.CornerRadius = 20;

    var mylabel = new UILabel(frame: new CoreGraphics.CGRect(10, 10, 80, 40));
    mylabel.Text = "MUMBAI";
    myView.Add(mylabel);

    UIButton button = new UIButton();


    button.Frame = new CoreGraphics.CGRect(mylabel.Frame.X + mylabel.Frame.Width, 10f, 40, 25);
    button.SetTitle("Title", UIControlState.Normal);
    button.SetBackgroundImage(UIImage.FromBundle("MyImage"),UIControlState.Normal);
    myView.Add(button);

    View.Add(myView);

这里你需要做框架计算,上面只是我放的一些示例框架。

所以最终你会让这些视图水平堆叠,当用户点击“x”按钮时,你会用动画改变框架。

【讨论】:

    【解决方案2】:

    试试这个

    https://github.com/nmilcoff/TagsView

    上手超级简单:

    public class ViewController : UIViewController
    {
        private TagListView tagsView;
    
        public override void ViewDidLoad()
        {
            // code
            this.tagsView = new TagListView()
            {
                // you can customize properties here!
            };
    
            this.View.AddSubview(this.tagsView);
    
            this.View.AddConstraints(        
                // Add your constraints!
            );
    
            // you can attach a source object to each tag
            var myObject = new MyModel { Title = "I'm a MyModel!" };
            this.tagsView.AddTag(myObject.Title, myObject); 
    
            // but, if none is provided, it will be the text string 
            this.tagsView.AddTag("I'm a simple tag!"); 
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多