小编iOS*_*eer的帖子

Xamarin:如何从iOS库项目加载图像

我有一个用MvvmCross设计的Xamarin项目.有子项目:

  • 核心(PCL)
  • ViewModel(PCL)
  • iOS(可执行文件)

如果我将图像添加到我的iOS项目(Resoureces/Images/test_image.png),那么我可以使用以下代码加载它:

UIImage image = UIImage.FromBundle("Images/test_icon.png");
Run Code Online (Sandbox Code Playgroud)

现在,我想使用一个新的子项目

  • 控件(iOS库)

该库应该加载图像.我在Controls(Resoureces/Images/test_image.png)中添加了一个图像

但我无法在Controls proj中加载此图像.

我的问题:如何从iOS库加载图像?

    public class MyButton : UIButton
    {
        public MyButton () : base()
        {
            Initialize ();
        }

        void Initialize()
        {
            // load image from bundle
            UIImage image = UIImage.FromBundle("Images/test_icon.png");
            // image is null
            this.SetImage (image, UIControlState.Normal);
        }
    }
Run Code Online (Sandbox Code Playgroud)

而ViewController类是:

    public partial class FirstView : MvxViewController
    {
        public FirstView () : base ("FirstView", null)
        {
        }

        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();

            // load image from …
Run Code Online (Sandbox Code Playgroud)

c# uiimage xamarin.ios mvvmcross xamarin

7
推荐指数
1
解决办法
6131
查看次数

UIAlertController仅在2秒后解除

我希望在呈现后立即解雇,但只能在2秒后才能解决.这该怎么做?

这是我在UILabel上从UITapGestureRecognizer调用的方法.

- (IBAction)labelTaped:(UITapGestureRecognizer *)sender {
  if (sender.state == UIGestureRecognizerStateEnded) {
    CGRect frame = CGRectNull;
    NSString *message = nil;
    // ...
    // some code
    /// ...
    if (message) {
        // show info alert
        __weak __typeof(self)weakSelf = self;
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil
                                                                       message:message
                                                                preferredStyle:UIAlertControllerStyleActionSheet];

        UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"alert_ok", @" - ")
                                                               style:UIAlertActionStyleCancel
                                                             handler:^(UIAlertAction * action) {
                                                                 if ([weakSelf.dismissAlertTimer isValid]) {
                                                                     [weakSelf.dismissAlertTimer invalidate];
                                                                 }
                                                             }];
        [alert addAction:cancelAction];

        UIPopoverPresentationController *popoverController = alert.popoverPresentationController;
        popoverController.sourceRect = frame;
        popoverController.sourceView = sender.view;


        [self.mainController presentViewController:alert animated:YES …
Run Code Online (Sandbox Code Playgroud)

objective-c ipad ios

6
推荐指数
1
解决办法
5700
查看次数

标签 统计

c# ×1

ios ×1

ipad ×1

mvvmcross ×1

objective-c ×1

uiimage ×1

xamarin ×1

xamarin.ios ×1