-2
한 클래스에서 확장 메서드를 참조하려고하지만 다음 오류가 발생합니다. "오류 : UIColor에 'FromHex'에 대한 정의가 없습니다. 내 설정은 다음과 같습니다. 내 오류가 발생한 줄의 시작 부분에 화살표를 추가했습니다 (화살표는 내 코드의 일부가 아닙니다). 호출 클래스에서 확장 메서드를 사용할 수 없습니다.
나는 경고 클래스가 있습니다using System;
using UIKit;
using System.Linq;
using MyApp.iOS;
[assembly: Xamarin.Forms.Dependency(typeof(MyApp.iOS.Alert))]
namespace MyApp.iOS {
public class Alert : IAlert {
public void ShowAlert(string title, string message, string button) {
ShowAlert(title, message, button, null);
}
public void ShowAlert(string title, string message, string button, string hexColor) {
var okAlertController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);
okAlertController.AddAction(UIAlertAction.Create(button, UIAlertActionStyle.Default, null));
if (hexColor != null) {
UIView firstSubView = okAlertController.View.Subviews.First();
UIView alertContentView = firstSubView.Subviews.First();
foreach (UIView subSubView in alertContentView.Subviews) {
--> subSubView.BackgroundColor = UIColor.FromHex(hexColor); // This line is where I'm getting the error
}
okAlertController.View.TintColor = UIColor.Black;
}
var window = UIApplication.SharedApplication.KeyWindow;
var viewController = window.RootViewController;
while (viewController.PresentedViewController != null) viewController = viewController.PresentedViewController;
var navigationController = viewController as UINavigationController;
if (navigationController != null) viewController = navigationController.ViewControllers.Last();
viewController.PresentViewController(okAlertController, true, null);
}
}
}
을 그리고 나는 UIColorExtensions 클래스가 있습니다
using System;
using System.Globalization;
using UIKit;
namespace MyApp.iOS {
public static class UIColorExtensions {
public static UIColor FromHex(this UIColor color, string hex) {
float a = 255, r = 0, g = 0, b = 0;
if (hex.StartsWith("#")) {
string hexColor = hex.Substring(1);
if (hexColor.Length == 8) {
float.TryParse(hexColor.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out a);
hexColor = hexColor.Substring(2, 6);
}
if (hexColor.Length == 6) {
float.TryParse(hexColor.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out r);
float.TryParse(hexColor.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out g);
float.TryParse(hexColor.Substring(6, 2), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out b);
}
return UIColor.FromRGBA(r, g, b, a);
}
return null;
}
}
}
내가 잘못된 일을 할 수 있는지 알아낼 수 있습니다. 여기
는 지금까지 시도했습니다 내용은 다음과 같습니다- 는 IDE
- 청소를 다시 시작, 내 경고 클래스의 네임 스페이스 선 위의 조립 라인을 제거하기
- 을 재건