小编Yos*_*far的帖子

无法更改UITableViewCell背景颜色

我有UITableViewCell适合的UITableView,但不知何故我进入编辑风格模式时无法改变背景颜色..我已经尝试了网上的所有内容,整天搜索,但仍然无法修复它(我已经搜索过了) StackOverflow也是如此).请帮我.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    MainTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {

        NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"MainTableViewCell" owner:nil options:nil];

        for (UIView *view in views) {
            if([view isKindOfClass:[UITableViewCell class]])
            {
                cell = (MainTableViewCell *)view;
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

iphone xcode objective-c uitableview ios

5
推荐指数
2
解决办法
8701
查看次数

UITableViewCell图像对齐到右边,可能吗?

将图像添加到表格单元格时,默认情况下会向左移动:

cell.imageView.image = [UIImage imageNamed:[arrImages objectAtIndex:indexPath.row]];
Run Code Online (Sandbox Code Playgroud)

如何更改UITableViewCell中的每个图像将自动向右移动,textLabel将在图像左侧10px.

非常感谢!

iphone xcode objective-c uitableview ios

5
推荐指数
2
解决办法
1万
查看次数

运行1个自定义shell脚本冻结

我正在构建一个框架,在尝试使用自定义shell脚本代码编译生产框架时,它会在此步骤中冻结.

这是自定义shell脚本代码:

# define output folder environment variable
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal

# Step 1. Build Device and Simulator versions
xcodebuild -target SomeSDK ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos  BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
xcodebuild -target SomeSDK -configuration ${CONFIGURATION} -sdk iphonesimulator -arch i386 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"

# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"

# Step 2. Create universal binary file using lipo
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a"

# Last touch. copy the header files. Just for convenience
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/"
Run Code Online (Sandbox Code Playgroud)

这是一个冻结的图像:

自定义shell脚本

我该如何解决这个问题?为什么会这样?

sdk xcode frameworks ios

5
推荐指数
1
解决办法
4058
查看次数

使用Swift创建一个Paging UICollectionView

我正在尝试使用分页创建一个UICollectionView,并且每个项目的最大宽度为250磅,我已设法创建它,但我有2个问题:第一个项目不是应该开始,但是在开始时有更多空间当我尝试滑动时,总有一些东西不会让我滑动.

这是它的样子:

视频链接

这是我的代码:

CenterCellCollectionFlowLayout.swift

class CenterCellCollectionViewFlowLayout: UICollectionViewFlowLayout {

    override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]? {

        var attributesToReturn:[UICollectionViewLayoutAttributes] = super.layoutAttributesForElementsInRect(rect) as! [UICollectionViewLayoutAttributes]

        for var i = 0 ; i < attributesToReturn.count ; i++
        {
            var currentLayoutAttributes: UICollectionViewLayoutAttributes = attributesToReturn[i]
            var maximumSpacing: CGFloat = 50
            let origin: CGFloat
            if i - 1 >= 0 {
                let previousLayoutAttributes = attributesToReturn[i - 1]
                origin = previousLayoutAttributes.frame.maxX
            } else {
                origin = 0
            }

            if origin + maximumSpacing + currentLayoutAttributes.frame.size.width < self.collectionViewContentSize().width
            {
                var …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview uicollectionviewlayout swift

5
推荐指数
2
解决办法
2万
查看次数

向应用程序发送静默推送通知,更新位置并在后台发送到服务器

我想向后台应用程序发送静默推送通知,然后获取当前用户位置并将其发送到 Web 服务。

我实现了推送通知方法以及这两个方法:

- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    NSDate *fetchStart = [NSDate date];

    [self sendLocationToServerWithCompletionHandler:^(UIBackgroundFetchResult result) {
        completionHandler(result);

        NSDate *fetchEnd = [NSDate date];
        NSTimeInterval timeElapsed = [fetchEnd timeIntervalSinceDate:fetchStart];
        NSLog(@"Background Fetch Duration: %f seconds", timeElapsed);

    }];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{

}
Run Code Online (Sandbox Code Playgroud)

我还创建了一个将位置发送到服务器的方法:

- (void)sendLocationToServerWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    NSDictionary *params = @{
                             @"UserId"      : self.userId,
                             @"Latitude"    : self.latitude,
                             @"Longitude"   : self.longitude
                             }

    ServerManager *manager = [ServerManager sharedManager];
    [manager sendLocationToServerWithCompletion:^(BOOL success) {

        if (success)
        {
            completionHandler(UIBackgroundFetchResultNewData);
        } …
Run Code Online (Sandbox Code Playgroud)

objective-c push-notification ios background-task background-fetch

5
推荐指数
1
解决办法
2578
查看次数

在动画时更改UIActivityIndi​​cator的颜色

是否可以在仍然动画时更改UIActivityIndi​​catorView的颜色?如果有人有这个问题,那么你可以建议我

iphone objective-c uiactivityindicatorview ios

4
推荐指数
1
解决办法
5980
查看次数

创建自定义弹出/警报UIView/UIViewController的正确方法

我已经为iOS开发了很长一段时间了,但我总是遇到自定义警报/弹出窗口的问题,我只是不知道在所有其他视图中添加自定义视图作为弹出窗口的正确方法是什么应用程序.

我已经在网上查了一下,有几种方法可以做到,但创建这些自定义提醒/弹出窗口的最佳方法是什么?

有一个CustomViewController类,这是我创建它并将其添加为弹出窗口的方式:

  1. 创建一个新的 UIViewController

  2. 添加UIView里面UIViewController的XIB文件作为一个孩子self.view(这将举行内部弹出元素)

  3. 在UIViewController用于呈现视图的内部添加此方法:

    - (void)presentViewController
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.window.windowLevel = UIWindowLevelStatusBar;
        self.window.screen = [UIScreen mainScreen];
        [self.window makeKeyAndVisible];
    
        UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
        [mainWindow setUserInteractionEnabled:NO];
        [self.window addSubview:self.view];
    
        self.view.alpha = 0.0f;
        self.backgroundImage.image = [self takeSnapshot];
    
        [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
    
            self.view.transform = CGAffineTransformIdentity;
            self.view.alpha = 1.0f;
    
        } completion:nil];
    }
    
    Run Code Online (Sandbox Code Playgroud)
  4. 在UIViewController删除视图中添加此方法:

    - (void)dismissShareViewController
    {
        [UIView animateWithDuration:DEFAULT_ANIMATION_DURATION …
    Run Code Online (Sandbox Code Playgroud)

objective-c uiviewcontroller uiview ios

4
推荐指数
1
解决办法
8316
查看次数

计算UILabel中可见文本的范围

我有一个UILabel固定大小的文本,我设置的文本长度UILabel可以是 200、5 或 500 个字符。我想要做的是计算UILabel在当前UILabel大小下可以放入多少可见文本。

为什么我要这样做?因为我想在...Read more文本的末尾添加一个文本,但不是在整个文本的末尾,只是在UILabel.

提前致谢。

objective-c nsattributedstring uilabel ios

4
推荐指数
1
解决办法
8027
查看次数

更改按钮的PDF矢量图像的tintColor

我已将PDF图像作为资产添加到Xcode,我想更改tintColor图像的 ,但没有成功。

我尝试添加User Defined Runtime Attributes,但它不起作用。

也尝试过以编程方式更改,但行不通。

self.buttonBringFriend.imageView.tintColor = UIColor.white
Run Code Online (Sandbox Code Playgroud)

有没有人有办法解决吗?

Xcode 11.1 斯威夫特 5.1

ios swift swift5 xcode11.1

4
推荐指数
2
解决办法
3085
查看次数

即使userInteractionEnabled = NO,也会在firstResponder上显示UITextField键盘

我有一个UITextField是第一响应者.我想在进入视图时显示键盘,但我想这样做,用户将无法编辑它,光标也会一直隐藏.

当您单击键盘字母时,它将被写入UITextField,但用户将无法在那里编辑任何内容,甚至不能进行复制.

谢谢!

iphone objective-c uitextfield uikeyboard ios

3
推荐指数
1
解决办法
3999
查看次数