uikit

How to restrict rightBarButtonItem size in UINavigationBar?

拥有回忆 提交于 2019-12-23 03:26:28
问题 I create a rightBarButtonItem with this method : - (UIBarButtonItem *)customBarButtonWithSelector:(SEL)callback { UIButton *customButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; customButton.bounds = CGRectMake(0, 0, 30.0f, 30.0f); return [[[UIBarButtonItem alloc] initWithCustomView:customButton] autorelease]; } At execution time the selector is fired when the bar is touched outside the button (near the middle). Is there a way to restrict the event responder in the defined bounds

How to save a UIImage to the application's Bundle?

折月煮酒 提交于 2019-12-23 02:40:17
问题 I am currently getting images from the 'Documents' directory (using -imageWithContentsOfFile:) with no problems except that I cannot get the images to display immediately (for example as soon as touchesEnded was called). I am assuming that this has to do with image caching and that image objects created in the above way are not cached? So, I figure, I will cache the image object after creating it and then use the cached image using -imageNamed:. So how can I save a UIImage object to the

How to handle touch gestures in SwiftUI in Swift UIKit Map component?

匆匆过客 提交于 2019-12-23 02:28:39
问题 I tried to handle Map UIKit component gestures in SwiftUI application. Xcode shows this warning: "String literal is not a valid Objective-C selector" // Binding to UIKit component import SwiftUI import MapKit struct MapView: UIViewRepresentable { class Coordinator: NSObject, MKMapViewDelegate { @Binding var selectedPin: MapPin? init(selectedPin: Binding<MapPin?>) { self._selectedPin = selectedPin } func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) { guard let pin = view

UITableView inside UITableViewCell with dynamic height

╄→尐↘猪︶ㄣ 提交于 2019-12-23 01:07:39
问题 I need to put UITableView inside UITableViewCell with auto-layout because second table has different number of rows and one row can have different height. This is my ViewController class ViewController: UIViewController { let tableView = UITableView() let cellId = "firstTableCellId" override func viewDidLoad() { super.viewDidLoad() setupView() tableView.reloadData() view.backgroundColor = UIColor.gray } func setupView() { tableView.delegate = self tableView.dataSource = self tableView

Label text in UICollectionViewCell not updating

前提是你 提交于 2019-12-22 18:37:41
问题 I'm trying to change the text of a UILabel in a UICollectionViewCell after the UICollectionViewCell has loaded, when tapping a button . But the label doesn't update on the screen. The console shows that the text property of the label is updated, but it seems the label isn't redrawn with the new text. Is this a known problem with UICollectionViewCells ? Some kind of caching issue, perhaps? Do I need to reload the cell, or the entire collection view for the update to show? 回答1: Because the cell

Scaling a font on a multilined UIButton depending on a device size

前提是你 提交于 2019-12-22 11:36:03
问题 Current setup: I have a multilined UIButton which is added to its superview (an ordinary UIView ). Button's width is 90% of its superview. So when its superview's size changes, label's width changes accordingly due to Autolayout constraints. Next, inside of viewDidLoad method I did this: //Line break mode and Font size ( are set in Interface Builder myButton.titleLabel?.adjustsFontSizeToFitWidth = true myButton.titleLabel?.minimumScaleFactor = 15.0 myButton.titleLabel?.numberOfLines = 2 So

Change color of selectedRow in UIPickerView, also when rolling

眉间皱痕 提交于 2019-12-22 11:31:21
问题 I have to change the color of the selected row in a UIPickerView . I did managed to change the color, i know that the question already have several replies, anyway those do not satisfy me: with those implementation, the animation of the pickerview is glitchy and i don't like it. This is the code of the current solution func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView { var label: UILabel if view == nil { label =

Pull down UIScrollView and hold y position

空扰寡人 提交于 2019-12-22 11:27:48
问题 I'm trying to fire an action when UIScrollView is pulled down to a certain point. This is what I have right now: - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView.contentOffset.y == -100.0) { NSLog(@"Trigger"); [scrollView setContentOffset:CGPointMake(0.0, -200.0) animated:YES]; } } This kind of works, until I end my touch event and then UIScrollView returns to it's original position. Any idea how to solve this? 回答1: Check for range instead of single pixel as scrollView

How to set an NSArray in NSUserDefaults?

好久不见. 提交于 2019-12-22 11:02:32
问题 I'm wondering why there is a -arrayForKey: method, but no -setArrayForKey: method. How could I set that array? 回答1: Just use setObject:forKey: . I guess the reason that there's a special arrayForKey: and dictionaryForKey: etc. is that you get better type safety and don't have to cast. If you use these methods and the element in the defaults does not match the type, then nil is returned. 回答2: arrayForKey and dictionaryForKey are getters. Use setObject to set an array. 回答3: - (void)setObject:

Strange @IBAction conflict or bug? (Swift)

让人想犯罪 __ 提交于 2019-12-22 10:44:14
问题 So I got this code for my simple iOS app. When I press the touchPressed button, the button should get a new random location on the screen and the labelScore should update itself with the number of button touches. A friend of mine tried this in Objective-C and it works. The problem is: I have the newScore() in touchedPressed and the button doesn't get a new location. If I comment newScore(), the random location action works. Thanks in advance. // ViewController.swift import UIKit import