How to add Badges on UIBarbutton item?

前端 未结 10 1710
广开言路
广开言路 2020-11-28 21:29

Hi friends am new to iphone developing. Am struggle with add badge values on UIBarbutton item on right side. I have tried but i can\'t solve this problem. Can anyone help me

10条回答
  •  暖寄归人
    2020-11-28 21:55

    I know this has been solved already,but I thought I might add what I have discovered to this answer for the sake of completeness.

    You can also just add MKNumberBadgeView directly to the view for the UIBarButtonItem. Using Monotouch (C#), this is how you get the view for the UIBarButtonItem

            //barbutton is some UIBarButtonItem. Make sure to check for view. In
            //ViewDidLoad(), the view for the barbutton might not exist yet.
            Selector sel = new Selector("view");
            var handle = Messaging.intptr_objc_msgSend(barbutton.Handle, sel.Handle);
            var view = Runtime.GetNSObject(handle) as UIView;
            var mkBadge = ...    //the badge
            view.Add(badge);
            view.Layer.ZPosition =  
    

    I'm sure it's easy to convert this to Obj-C. You will also need to play around with the Frame for the badge to get it to show up in the right place.

    This way you wont have to remove/add the view from the navigationbar.

提交回复
热议问题