2

我正在编写一些 Objective-C 代码,但我不知道为什么这不起作用:

buttonRect = CGRectMake(0,0,100.0,100.0);//error:incompatible types in assignment
CGRect newFrame = CGRectInset(buttonRect, -0.2, -0.2);//error:incompatible type for argument 1 of CGRectInset
button.frame = newFrame;

buttonRect 是在我的类中定义为实例变量的 CGRect,而 button 是 UIButton 也定义为实例变量。为什么这不起作用?我的头文件:

//
//  MyViewController.h
//  HelloWorld
//
//  Created by RCIX on 7/10/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface MyViewController : UIViewController {
    UITextField *textField;
    UILabel *label;
    NSString *string;
    UIButton *button;
    CGRect *buttonRect;
}

@property (nonatomic, assign) CGRect *buttonRect;
@property (nonatomic, retain) IBOutlet UITextField *textField;
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, retain) IBOutlet UIButton *button;
@property (nonatomic, retain) NSString *string;

- (IBAction)helloButtonDown:(id)sender;
- (IBAction)helloButtonUp:(id)sender;

@end
4

3 回答 3

8

buttonRect被声明为CGRect *- 即指向CGRect的指针。删除 splat,一切都会好起来的。

于 2009-07-14T01:00:54.133 回答
1

仔细检查 buttonRect:确定它没有被定义为 CGRect。

于 2009-07-14T00:47:45.593 回答
0

buttonRect 是在其他地方定义的,还是在定义时需要给它一个类型?

于 2009-07-14T00:46:25.423 回答