本文整理汇总了C#中NSMutableDictionary.SetValueForKey方法的典型用法代码示例。如果您正苦于以下问题:C# NSMutableDictionary.SetValueForKey方法的具体用法?C# NSMutableDictionary.SetValueForKey怎么用?C# NSMutableDictionary.SetValueForKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NSMutableDictionary
的用法示例。
在下文中一共展示了NSMutableDictionary.SetValueForKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterDefaultSettings
public static void RegisterDefaultSettings ()
{
var path = Path.Combine(NSBundle.MainBundle.PathForResource("Settings", "bundle"), "Root.plist");
using (NSString keyString = new NSString ("Key"), defaultString = new NSString ("DefaultValue"), preferenceSpecifiers = new NSString ("PreferenceSpecifiers"))
using (var settings = NSDictionary.FromFile(path))
using (var preferences = (NSArray)settings.ValueForKey(preferenceSpecifiers))
using (var registrationDictionary = new NSMutableDictionary ()) {
for (nuint i = 0; i < preferences.Count; i++)
using (var prefSpecification = preferences.GetItem<NSDictionary>(i))
using (var key = (NSString)prefSpecification.ValueForKey(keyString))
if (key != null)
using (var def = prefSpecification.ValueForKey(defaultString))
if (def != null)
registrationDictionary.SetValueForKey(def, key);
NSUserDefaults.StandardUserDefaults.RegisterDefaults(registrationDictionary);
#if DEBUG
SetSetting(SettingsKeys.UserReferenceKey, debugReferenceKey);
#else
SetSetting(SettingsKeys.UserReferenceKey, UIDevice.CurrentDevice.IdentifierForVendor.AsString());
#endif
Synchronize();
}
}
示例2: TwitterRequest
public TwitterRequest (string method, Uri url, IDictionary<string, string> paramters, Account account)
: base (method, url, paramters, account)
{
var ps = new NSMutableDictionary ();
if (paramters != null) {
foreach (var p in paramters) {
ps.SetValueForKey (new NSString (p.Value), new NSString (p.Key));
}
}
var m = TWRequestMethod.Get;
switch (method.ToLowerInvariant()) {
case "get":
m = TWRequestMethod.Get;
break;
case "post":
m = TWRequestMethod.Post;
break;
case "delete":
m = TWRequestMethod.Delete;
break;
default:
throw new NotSupportedException ("Twitter does not support the HTTP method '" + method + "'");
}
request = new TWRequest (new NSUrl (url.AbsoluteUri), ps, m);
Account = account;
}
示例3: Initialize
// Shared initialization code
void Initialize ()
{
repeatCount = 1;
var font = NSFont.UserFixedPitchFontOfSize (16);
textAttrs = new NSMutableDictionary ();
textAttrs.SetValueForKey (font, NSAttributedString.FontAttributeName);
}
示例4: ClassInitialize
public static void ClassInitialize()
{
// Create a Defaults dictionary
NSMutableDictionary defaultValues = new NSMutableDictionary();
// Archive the color object
NSData colorAsData = NSKeyedArchiver.ArchivedDataWithRootObject(NSColor.White);
// Put defaults in the dictionary
defaultValues.SetValueForKey(colorAsData, DefaultStrings.RMTableBgColorKey);
defaultValues.SetValueForKey(NSNumber.FromBoolean(true), DefaultStrings.RMEmptyDocKey);
// Register the dictionary of defaults
NSUserDefaults.StandardUserDefaults.RegisterDefaults(defaultValues);
Console.WriteLine("Registered defaults: {0}", defaultValues);
sFirstLaunch = true;
}
示例5: DidStartSession
void DidStartSession(object sender, KiipManagerDictEventArgs evt)
{
Console.WriteLine("Session started");
if(evt.Resource == null)
{
var alert = new UIAlertView("Kiip","Session created: No Promo",null,"OK");
alert.Show();
return;
}
NSMutableDictionary reward = new NSMutableDictionary(evt.Resource);
reward.SetValueForKey(NSNumber.FromInt32((int)KPViewPosition.FullScreen),new NSString("position"));
KPManager.SharedManager.PresentReward(reward);
(new UIAlertView("Kiip","Session created: Promo",null,"Ok")).Show();;
}
示例6: FinishedLaunching
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
viewController = new UrbanAirshipPushNotificationsViewController ();
window.RootViewController = viewController;
window.MakeKeyAndVisible ();
options = new NSDictionary ();
var takeOffOptions = new NSMutableDictionary ();
takeOffOptions.SetValueForKey (options, new NSString ("UAirshipTakeOffOptionsLaunchOptionsKey"));
UAPush.Shared.ResetBadge ();
UAirship.TakeOff (takeOffOptions);
return true;
}
示例7: Main
static void Main (string[] args)
{
NSApplication.Init ();//!!!Must be very first thing to run!!!
#if DEBUG
NSApplication.CheckForIllegalCrossThreadCalls = false;//causes wrong exceptions alluring that NSApplication.SharedApplication.InvokeOnMainThread doesnt work as expected
//WebInspector
NSUserDefaults userDefaults = NSUserDefaults.StandardUserDefaults;
NSMutableDictionary appDefaults = new NSMutableDictionary ();
appDefaults.SetValueForKey (NSObject.FromObject (true), new NSString ("WebKitDeveloperExtras"));
userDefaults.RegisterDefaults (appDefaults);
userDefaults.Synchronize ();
#endif
TinyIoCContainer.Current.Register<AppHelper.Data.Manager, Manager>(new Manager());
AppHelper.Data.ConnectDatabase();//TODO: noo has to be done async - otherwise will kill the app on huge db load due to timeout
NSApplication.Main (args);
}
示例8: RegisterDefaultsFromSettingsBundle
//UITabBarController TabController;
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public static void RegisterDefaultsFromSettingsBundle()
{
string settingsBundle = NSBundle.MainBundle.PathForResource("Settings", @"bundle");
if(settingsBundle == null) {
System.Console.WriteLine(@"Could not find Settings.bundle");
return;
}
NSString keyString = new NSString(@"Key");
NSString defaultString = new NSString(@"DefaultValue");
NSDictionary settings = NSDictionary.FromFile(Path.Combine(settingsBundle,@"Root.plist"));
NSArray preferences = (NSArray) settings.ValueForKey(new NSString(@"PreferenceSpecifiers"));
NSMutableDictionary defaultsToRegister = new NSMutableDictionary();
for (uint i=0; i<preferences.Count; i++) {
NSDictionary prefSpecification = new NSDictionary(preferences.ValueAt(i));
NSString key = (NSString) prefSpecification.ValueForKey(keyString);
if(key != null) {
NSObject def = prefSpecification.ValueForKey(defaultString);
if (def != null) {
defaultsToRegister.SetValueForKey(def, key);
}
}
}
NSUserDefaults.StandardUserDefaults.RegisterDefaults(defaultsToRegister);
}
示例9: SCBoxNode
public static SCNNode SCBoxNode (string title, CGRect frame, NSColor color, float cornerRadius, bool centered)
{
NSMutableDictionary titleAttributes = null;
NSMutableDictionary centeredTitleAttributes = null;
// create and extrude a bezier path to build the box
var path = NSBezierPath.FromRoundedRect (frame, cornerRadius, cornerRadius);
path.Flatness = 0.05f;
var shape = SCNShape.Create (path, 20);
shape.ChamferRadius = 0.0f;
var node = SCNNode.Create ();
node.Geometry = shape;
// create an image and fill with the color and text
var textureSize = new CGSize ();
textureSize.Width = NMath.Ceiling (frame.Size.Width * 1.5f);
textureSize.Height = NMath.Ceiling (frame.Size.Height * 1.5f);
var texture = new NSImage (textureSize);
texture.LockFocus ();
var drawFrame = new CGRect (0, 0, textureSize.Width, textureSize.Height);
nfloat hue, saturation, brightness, alpha;
(color.UsingColorSpace (NSColorSpace.DeviceRGBColorSpace)).GetHsba (out hue, out saturation, out brightness, out alpha);
var lightColor = NSColor.FromDeviceHsba (hue, saturation - 0.2f, brightness + 0.3f, alpha);
lightColor.Set ();
NSGraphics.RectFill (drawFrame);
NSBezierPath fillpath = null;
if (cornerRadius == 0 && centered == false) {
//special case for the "labs" slide
drawFrame.Offset (0, -2);
fillpath = NSBezierPath.FromRoundedRect (drawFrame, cornerRadius, cornerRadius);
} else {
drawFrame.Inflate (-3, -3);
fillpath = NSBezierPath.FromRoundedRect (drawFrame, cornerRadius, cornerRadius);
}
color.Set ();
fillpath.Fill ();
// draw the title if any
if (title != null) {
if (titleAttributes == null) {
var paraphStyle = new NSMutableParagraphStyle ();
paraphStyle.LineBreakMode = NSLineBreakMode.ByWordWrapping;
paraphStyle.Alignment = NSTextAlignment.Center;
paraphStyle.MinimumLineHeight = 38;
paraphStyle.MaximumLineHeight = 38;
var font = NSFont.FromFontName ("Myriad Set Semibold", 34) != null ? NSFont.FromFontName ("Myriad Set Semibold", 34) : NSFont.FromFontName ("Avenir Medium", 34);
var shadow = new NSShadow ();
shadow.ShadowOffset = new CGSize (0, -2);
shadow.ShadowBlurRadius = 4;
shadow.ShadowColor = NSColor.FromDeviceWhite (0.0f, 0.5f);
titleAttributes = new NSMutableDictionary ();
titleAttributes.SetValueForKey (font, NSAttributedString.FontAttributeName);
titleAttributes.SetValueForKey (NSColor.White, NSAttributedString.ForegroundColorAttributeName);
titleAttributes.SetValueForKey (shadow, NSAttributedString.ShadowAttributeName);
titleAttributes.SetValueForKey (paraphStyle, NSAttributedString.ParagraphStyleAttributeName);
var centeredParaphStyle = (NSMutableParagraphStyle)paraphStyle.MutableCopy ();
centeredParaphStyle.Alignment = NSTextAlignment.Center;
centeredTitleAttributes = new NSMutableDictionary ();
centeredTitleAttributes.SetValueForKey (font, NSAttributedString.FontAttributeName);
centeredTitleAttributes.SetValueForKey (NSColor.White, NSAttributedString.ForegroundColorAttributeName);
centeredTitleAttributes.SetValueForKey (shadow, NSAttributedString.ShadowAttributeName);
centeredTitleAttributes.SetValueForKey (paraphStyle, NSAttributedString.ParagraphStyleAttributeName);
}
var attrString = new NSAttributedString (title, centered ? centeredTitleAttributes : titleAttributes);
var textSize = attrString.Size;
//check if we need two lines to draw the text
var twoLines = title.Contains ("\n");
if (!twoLines)
twoLines = textSize.Width > frame.Size.Width && title.Contains (" ");
//if so, we need to adjust the size to center vertically
if (twoLines)
textSize.Height += 38;
if (!centered)
drawFrame.Inflate (-15, 0);
//center vertically
var dy = (drawFrame.Size.Height - textSize.Height) * 0.5f;
var drawFrameHeight = drawFrame.Size.Height;
drawFrame.Size = new CGSize (drawFrame.Size.Width, drawFrame.Size.Height - dy);
attrString.DrawString (drawFrame);
}
//.........这里部分代码省略.........
示例10: GetToken
void GetToken ()
{
// Register APNS Token to GCM
var options = new NSMutableDictionary ();
options.SetValueForKey (DeviceToken, Constants.RegisterAPNSOption);
options.SetValueForKey (new NSNumber (true), Constants.APNSServerTypeSandboxOption);
Log ("Get Token");
// Get our token
InstanceId.SharedInstance.Token (
Configuration.GcmSenderId,
Constants.ScopeGCM,
options,
(token, error) => Log ("GCM Registration ID: " + token));
}
示例11: IISaveImage
// Save the given image to a file at the given url.
// Returns true if successful, false otherwise.
public static bool IISaveImage(ImageView view, NSURL url, uint width, uint height)
{
ImageInfo image = view.Image;
bool result = false;
// If there is no image, no destination, or the width/height is 0, then fail early.
if ((url != null) && (width != 0) && (height != 0))
{
// Try to create a jpeg image destination at the url given to us
IntPtr imageDest = CGImageDestination.CreateWithURL(url, UTType.kUTTypeJPEG, 1, null);
if (imageDest != IntPtr.Zero)
{
// And if we can, then we can start building our final image.
// We begin by creating a CGBitmapContext to host our desintation image.
// Allocate enough space to hold our pixels
IntPtr imageData = Marshal.AllocHGlobal((int) (Marshal.SizeOf(typeof (UInt32))*width*height));
// Create the bitmap context
IntPtr bitmapContext = CGBitmapContext.Create(
imageData, // image data we just allocated...
width, // width
height, // height
8, // 8 bits per component
sizeof (UInt32)*width, // bytes per pixel times number of pixels wide
CGImage.GetColorSpace(image.fImageRef), // use the same colorspace as the original image
(CGBitmapInfo) CGImageAlphaInfo.kCGImageAlphaPremultipliedFirst); // use premultiplied alpha
// Check that all that went well
if (bitmapContext != IntPtr.Zero)
{
// Now, we draw the image to the bitmap context
IIDrawImageTransformed(ref image, bitmapContext, CGRect.CGRectMake(0.0f, 0.0f, width, height));
// We have now gotten our image data to the bitmap context, and correspondingly
// into imageData. If we wanted to, we could look at any of the pixels of the image
// and manipulate them in any way that we desire, but for this case, we're just
// going to ask ImageIO to write this out to disk.
// Obtain a CGImageRef from the bitmap context for ImageIO
IntPtr imageIOImage = CGBitmapContext.CreateImage(bitmapContext);
// Check if we have additional properties from the original image
if (image.fProperties != null)
{
// If we do, then we want to inspect the orientation property.
// If it exists and is not the default orientation, then we
// want to replace that orientation in the destination file
int orientation = IIGetImageOrientation(ref image);
if (orientation != 1)
{
// If the orientation in the original image was not the default,
// then we need to replace that key in a duplicate of that dictionary
// and then pass that dictionary to ImageIO when adding the image.
NSMutableDictionary prop = new NSMutableDictionary(image.fProperties);
orientation = 1;
prop.SetValueForKey(NSNumber.NumberWithInt(orientation), CGImageProperties.kCGImagePropertyOrientation);
// And add the image with the new properties
CGImageDestination.AddImage(imageDest, imageIOImage, prop);
// Clean up after ourselves
prop.Release();
}
else
{
// Otherwise, the image was already in the default orientation and we can just save
// it with the original properties.
CGImageDestination.AddImage(imageDest, imageIOImage, image.fProperties);
}
}
else
{
// If we don't, then just add the image without properties
CGImageDestination.AddImage(imageDest, imageIOImage, null);
}
// Release the image and the context, since we are done with both.
CGImage.Release(imageIOImage);
CGContext.Release(bitmapContext);
}
// Deallocate the image data
Marshal.FreeHGlobal(imageData);
// Finalize the image destination
result = CGImageDestination.Finalize(imageDest);
CFType.CFRelease(imageDest);
}
}
return result;
}
示例12: MakeGLDisplayListFirst
// Create the set of display lists for the bitmaps
bool MakeGLDisplayListFirst (char first, int count, int baseDL)
{
int curListIndex;
NSColor blackColor;
NSMutableDictionary attribDict;
int dListNum;
NSString currentChar;
char currentUnichar;
SizeF charSize;
RectangleF charRect;
NSImage theImage;
bool retval;
// Make sure the list isn't already under construction
GL.GetInteger (GetPName.ListIndex, out curListIndex);
if (curListIndex != 0) {
Console.WriteLine ("Display list already under construction");
return false;
}
// Save pixel unpacking state
GL.PushClientAttrib (ClientAttribMask.ClientPixelStoreBit);
GL.PixelStore (PixelStoreParameter.UnpackSwapBytes, 0);
GL.PixelStore (PixelStoreParameter.UnpackLsbFirst, 0);
GL.PixelStore (PixelStoreParameter.UnpackSkipPixels, 0);
GL.PixelStore (PixelStoreParameter.UnpackSkipRows, 0);
GL.PixelStore (PixelStoreParameter.UnpackRowLength, 0);
GL.PixelStore (PixelStoreParameter.UnpackAlignment, 0);
blackColor = NSColor.Black;
attribDict = new NSMutableDictionary ();
attribDict.SetValueForKey (font, NSAttributedString.FontAttributeName);
attribDict.SetValueForKey (NSColor.White, NSAttributedString.ForegroundColorAttributeName);
attribDict.SetValueForKey (blackColor, NSAttributedString.BackgroundColorAttributeName);
charRect.Location.X = charRect.Location.Y = 0;
theImage = new NSImage (new SizeF (0,0));
retval = true;
for (dListNum = baseDL, currentUnichar = first; currentUnichar < first + count;
dListNum++, currentUnichar++) {
currentChar = new NSString (Char.ToString (currentUnichar));
charSize = currentChar.StringSize (attribDict);
charRect.Size = charSize;
charRect = charRect.Integral ();
if (charRect.Size.Width > 0 && charRect.Size.Height > 0) {
theImage.Size = charRect.Size;
theImage.LockFocus ();
NSGraphicsContext.CurrentContext.ShouldAntialias = false;
blackColor.Set ();
NSBezierPath.FillRect (charRect);
currentChar.DrawString (charRect, attribDict);
theImage.UnlockFocus ();
if (!MakeDisplayList(dListNum, theImage)) {
retval = false;
break;
}
}
}
return retval;
}
示例13: RegisterDefaultSettings
private static void RegisterDefaultSettings()
{
var userDefaults = NSUserDefaults.StandardUserDefaults;
var appDefaults = new NSMutableDictionary();
appDefaults.SetValueForKey(NSObject.FromObject(true), new NSString("CollectAnonymousUsage"));
userDefaults.RegisterDefaults(appDefaults);
userDefaults.Synchronize();
}
示例14: showFullscreen
partial void showFullscreen()
{
Console.WriteLine("Show Notification");
AppDelegate appDelegate = (AppDelegate)UIApplication.SharedApplication.Delegate;
NSMutableArray queue = appDelegate.Resources;
UInt16 count = Convert.ToUInt16(queue.Count - 1);
while(queue.Count > 0)
{
NSMutableDictionary reward = new NSMutableDictionary(new NSDictionary(queue.ValueAt(count)));
reward.SetValueForKey(NSNumber.FromInt32((int)KPViewPosition.FullScreen),new NSString("position"));
KPManager.SharedManager.PresentReward(reward);
queue.RemoveObject((int)queue.Count - 1);
}
// NSLog(@"show fullscreen");
// MainAppDelegate *appDelegate = (MainAppDelegate *)[[UIApplication sharedApplication] delegate];
//
// NSMutableArray *queue = [appDelegate resources];
// while ([queue count] > 0) {
// NSMutableDictionary* reward = [NSMutableDictionary dictionaryWithDictionary:[queue objectAtIndex:[queue count] - 1]];
// [reward setObject:[NSNumber numberWithInt:kKPViewPosition_FullScreen] forKey:@"position"];
//
// [[KPManager sharedManager] presentReward:reward];
// [queue removeObjectAtIndex:[queue count] - 1];
// }
}
示例15: ToSplunkNSException
/// <summary>
/// Helper System.Exception extension method.
/// </summary>
/// <returns>The Splunk>MINT NSException.</returns>
/// <param name="exception">The System.Exception.</param>
public static NSException ToSplunkNSException(this Exception exception)
{
NSMutableDictionary dictionary = new NSMutableDictionary ();
dictionary.SetValueForKey (
NSObject.FromObject(NSString.FromData(NSData.FromString(exception.StackTrace.Trim()), NSStringEncoding.UTF8)),
NSString.FromData(NSData.FromString("SplunkMint-Xamarin-Exception-Stacktrace"), NSStringEncoding.UTF8));
string[] messages = exception.Message.Split (new [] { '\n' }, 1, StringSplitOptions.RemoveEmptyEntries);
string message = null;
if (messages != null &&
messages [0] != null)
{
message = messages [0];
}
return new NSException (exception.GetType ().FullName, message != null ? message : exception.Message, dictionary);
}